fix bootstrapfs names, and add fcdistro to extension tarballs
[bootstrapfs.git] / build.sh
1 #!/bin/bash
2 #
3 # Build bootstrapfs-*.tar.bz2, the reference image(s) for PlanetLab nodes.
4 #
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Marc E. Fiuczynski <mef@cs.princeton.edu>
7 # Copyright (C) 2005-2007 The Trustees of Princeton University
8 #
9 # $Id$
10 #
11
12 #
13 # This will build the bootstrafs-*.tar.bz2 images, which comprises
14 # the base root image on the node, then create the ${NAME} bootstrap image
15 # which is made up of just the additional files needed for a ${NAME} nodegroup 
16 # node.
17 #
18 # It is expected to be in sync with the getNodeFlavour PLCAPI method
19
20 PATH=/sbin:/bin:/usr/sbin:/usr/bin
21
22 # in the PlanetLab build environment, our dependencies are checked out 
23 # into directories at the same level as us.
24 if [ -d ../build ] ; then
25     PATH=$PATH:../build
26     srcdir=../
27 else
28     echo "Error: Could not find ../build in $(pwd)"
29     exit 1
30 fi
31
32 export PATH
33
34 . build.common
35
36 pl_process_fedora_options $@
37 shiftcount=$?
38 shift $shiftcount
39
40 # expecting fcdistro and pldistro on the command line
41 pldistro=$1; shift
42 fcdistro=${pl_DISTRO_NAME}
43 arch=${pl_DISTRO_ARCH}
44 nodefamily=${pldistro}-${fcdistro}-${arch}
45 extensionfamily=${fcdistro}-${arch}
46
47 # Do not tolerate errors
48 set -e
49
50 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
51 # unless the installation is running inside the BootCD environment. We
52 # would like to pretend that we are.
53 export PL_BOOTCD=1
54
55 # Populate a minimal /dev and then the files for the base bootstrapfs content
56 vref=${PWD}/base
57 install -d -m 755 ${vref}
58 pl_root_makedevs $vref
59
60 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.pkgs)
61 echo "* Building Bootstrapfs for ${pldistro}: $(date)"
62 # -k = exclude kernel* packages
63 pl_root_mkfedora ${vref} ${pldistro} $pkgsfile
64
65 # optionally invoke a post processing script after packages from
66 # $pkgsfile have been installed
67 postfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.post || : )
68 [ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vref} || : ; }
69
70 displayed=""
71
72 # for distros that do not define bootstrapfs variants
73 pkgs_count=$(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs 2> /dev/null | wc -l)
74 [ $pkgs_count -gt 0 ] && for pkgs in $(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs); do
75     NAME=$(basename $pkgs .pkgs | sed -e s,bootstrapfs-,,)
76
77     [ -z "$displayed" ] && echo "* Handling ${pldistro} bootstrapfs extensions"
78     displayed=true
79
80     extension_plain=bootstrapfs-${NAME}-${extensionfamily}.tar
81     extension_name=bootstrapfs-${NAME}-${extensionfamily}.tar.bz2
82
83     echo "* Start Building $extension_name: $(date)"
84
85     # "Parse" out the packages and groups for yum
86     packages=$(pl_getPackages $fcdistro $pldistro $pkgs)
87     groups=$(pl_getGroups $fcdistro $pldistro $pkgs)
88     echo "${NAME} has the following packages : ${packages}"
89     echo "${NAME} has the following groups : ${groups}"
90
91     vdir=${PWD}/${pldistro}-filesystems/${NAME}
92     rm -rf ${vdir}/*
93     install -d -m 755 ${vdir}
94
95     # Clone the base reference to the bootstrap fs
96     (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
97     rm -f ${vdir}/var/lib/rpm/__db*
98
99     # Install the system vserver specific packages
100     [ -n "$packages" ] && yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y install $packages
101     for group_plus in $groups; do
102         group=$(echo $group_plus | sed -e "s,+++, ,g")
103         yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y groupinstall "$group"
104     done
105
106
107     if [ -f "${vdir}/proc/cpuinfo" ] ; then
108         echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
109         umount ${vdir}/proc
110     fi
111
112     # optionally invoke a post processing script after packages from
113     # $pkgs have been installed
114     postfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs-${NAME}.post || : )
115     [ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vdir} || : ; }
116
117     # Create a copy of the ${NAME} bootstrap filesystem w/o the base
118     # bootstrap filesystem and make it smaller.  This is a three step
119     # process:
120
121     # step 1: clean out yum cache to reduce space requirements
122     yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y clean all
123
124     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
125     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
126     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
127     let headcount=$linecount-3
128     let tailcount=$headcount-1
129     # get rid of the last 3 lines of the rsync output
130     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
131     # get rid of the first line of the rsync output
132     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
133     # post process rsync output to get rid of symbolic link embellish output
134     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
135     rm -f ${vdir}.changes.*
136
137     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
138     install -d -m 755 ${vdir}-tmp/
139     rm -rf ${vdir}-tmp/*
140     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
141     rm -rf ${vdir}
142     rm -f  ${vdir}.changes
143     mv ${vdir}-tmp ${vdir}
144     
145     echo -n "* tar $extension_name s=$(date +%H-%M-%S)"
146     tar -cpf ${pldistro}-filesystems/$extension_plain -C ${vdir} .
147     echo -n " m=$(date +%H-%M-%S) "
148     bzip2 --compress --stdout ${pldistro}-filesystems/$extension_plain > ${pldistro}-filesystems/$extension_name
149     echo " e=$(date +%H-%M-%S) "
150 done
151
152 # Build the base Bootstrap filesystem
153 # clean out yum cache to reduce space requirements
154 yum -c ${vref}/etc/mkfedora-yum.conf --installroot=${vref} -y clean all
155
156 bootstrapfs_plain=bootstrapfs-${nodefamily}.tar
157 bootstrapfs_name=bootstrapfs-${nodefamily}.tar.bz2
158 echo -n "* tar $bootstrapfs_name s=$(date +%H-%M-%S)"
159 tar -cpf $bootstrapfs_plain -C ${vref} .
160 echo -n " m=$(date +%H-%M-%S) "
161 bzip2 --compress --stdout $bootstrapfs_plain > $bootstrapfs_name
162 echo " e=$(date +%H-%M-%S) "
163
164 exit 0