previous change trashed the -k option to mkfedora
[bootstrapfs.git] / build.sh
1 #!/bin/bash
2 #
3 # Build PlanetLab-Bootstrap.tar.bz2, the reference image for PlanetLab
4 # nodes.
5 #
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Marc E. Fiuczynski <mef@cs.princeton.edu>
8 # Copyright (C) 2005-2007 The Trustees of Princeton University
9 #
10 # $Id: buildnode.sh,v 1.12.6.1 2007/08/30 20:09:20 mef Exp $
11 #
12
13 PATH=/sbin:/bin:/usr/sbin:/usr/bin
14
15 # In both a normal CVS environment and a PlanetLab RPM
16 # build environment, all of our dependencies are checked out into
17 # directories at the same level as us.
18 if [ -d ../build ] ; then
19     PATH=$PATH:../build
20     srcdir=../
21 else
22     echo "Error: Could not find $(cd ../.. && pwd -P)/build/"
23     exit 1
24 fi
25
26 export PATH
27
28 . build.common
29
30 pl_process_fedora_options $@
31 shiftcount=$?
32 shift $shiftcount
33
34 # pldistro expected as $1 - defaults to planetlab
35 pldistro=planetlab
36 [ -n "$@" ] && pldistro=$1
37
38 # Do not tolerate errors
39 set -e
40
41 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
42 # unless the installation is running inside the BootCD environment. We
43 # would like to pretend that we are.
44 export PL_BOOTCD=1
45
46 # "Parse" out the packages and groups into the options passed to mkfedora
47 # -k = exclude kernel* packages
48 lst="${pldistro}-base.lst"
49 popts=$(pl_getPackagesOptions2 ${pl_DISTRO_NAME} $lst)
50 gopts=$(pl_getGroupsOptions2 ${pl_DISTRO_NAME} $lst)
51
52 options="${popts} ${gopts} -k"
53
54 echo "+++++++++++++OPTIONS = ${options}"
55
56 # Populate a minimal /dev and then the files for the base PlanetLab-Bootstrap content
57 vref=${PWD}/base
58 install -d -m 755 ${vref}
59 pl_mkfedora ${vref} ${options}
60
61 for lst in ${pldistro}-filesystems/*.lst ; do
62     NAME=$(basename $lst .lst)
63
64     echo "--------START BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
65
66     # "Parse" out the packages and groups for yum
67     packages=$(pl_getPackages2 ${pl_DISTRO_NAME} $lst)
68     groups=$(pl_getGroups2 ${pl_DISTRO_NAME} $lst)
69     echo "${NAME} has the following packages and groups: ${packages} ${groups}"
70
71     vdir=${PWD}/${pldistro}-filesystems/${NAME}
72     rm -rf ${vdir}/*
73     install -d -m 755 ${vdir}
74
75     # Clone the base reference to the bootstrap fs
76     (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
77     rm -f ${vdir}/var/lib/rpm/__db*
78
79     # Install the system vserver specific packages
80     [ -n "$packages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $packages
81     [ -n "$groups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $groups
82
83     if [ -f "${vdir}/proc/cpuinfo" ] ; then
84         echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
85         umount ${vdir}/proc
86     fi
87
88     # Create a copy of the ${NAME} bootstrap filesystem w/o the base
89     # bootstrap filesystem and make it smaller.  This is a three step
90     # process:
91
92     # step 1: clean out yum cache to reduce space requirements
93     yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
94
95     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
96     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
97     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
98     let headcount=$linecount-3
99     let tailcount=$headcount-1
100     # get rid of the last 3 lines of the rsync output
101     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
102     # get rid of the first line of the rsync output
103     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
104     # post process rsync output to get rid of symbolic link embellish output
105     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
106     rm -f ${vdir}.changes.*
107
108     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
109     install -d -m 755 ${vdir}-tmp/
110     rm -rf ${vdir}-tmp/*
111     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
112     rm -rf ${vdir}
113     rm -f  ${vdir}.changes
114     mv ${vdir}-tmp ${vdir}
115
116     echo "--------STARTING tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
117     tar -cpjf ${pldistro}-filesystems/PlanetLab-Bootstrap-${NAME}.tar.bz2 -C ${vdir} .
118     echo "--------FINISHED tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
119     echo "--------DONE BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
120 done
121
122 # Build the base Bootstrap filesystem
123 # clean out yum cache to reduce space requirements
124 yum -c ${vref}/etc/yum.conf --installroot=${vdir} -y clean all
125 echo "--------STARTING tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
126 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C ${vref} .
127 echo "--------FINISHED tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
128
129 exit 0