fix: yum clean all installroot was pointing at the wrong directory
[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
14 #
15 # This will build the Planetlab-Bootstrap.tar.bz2, which comprises
16 # the base root image on the node, then create the ${NAME} bootstrap image
17 # which is made up of just the additional files needed for a ${NAME} nodegroup 
18 # node.
19 #
20
21 PATH=/sbin:/bin:/usr/sbin:/usr/bin
22
23 # In both a normal CVS environment and a PlanetLab RPM
24 # build environment, all of our dependencies are checked out into
25 # directories at the same level as us.
26 if [ -d ../build ] ; then
27     PATH=$PATH:../build
28     srcdir=../
29 else
30     echo "Error: Could not find $(cd ../.. && pwd -P)/build/"
31     exit 1
32 fi
33
34 export PATH
35
36 . build.common
37
38 pl_process_fedora_options $@
39 shiftcount=$?
40 shift $shiftcount
41
42 # pldistro expected as $1 - defaults to planetlab
43 pldistro=planetlab
44 [ -n "$@" ] && pldistro=$1
45
46 # Do not tolerate errors
47 set -e
48
49 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
50 # unless the installation is running inside the BootCD environment. We
51 # would like to pretend that we are.
52 export PL_BOOTCD=1
53
54 echo "+++++++++++++pkgsfile=$pkgsfile (and -k)"
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_root_makedevs $vref
60
61 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.pkgs)
62 # -k = exclude kernel* packages
63 pl_root_mkfedora -k -f $pkgsfile ${vref} 
64
65 # optionally invoke a post processing script after packages from
66 # $pkgsfile have been installed
67 pkgsdir=$(dirname $pkgsfile)
68 pkgsname=$(basename $pkgsfile .pkgs)
69 postfile="${pkgsdir}/${pkgsname}.post"
70 [ -f $postfile ] && /bin/bash $postfile ${vref} || :
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     echo "--------START BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
78
79     # "Parse" out the packages and groups for yum
80     packages=$(pl_getPackages ${pl_DISTRO_NAME} $pkgs)
81     groups=$(pl_getGroups ${pl_DISTRO_NAME} $pkgs)
82     echo "${NAME} has the following packages : ${packages}"
83     echo "${NAME} has the following groups : ${groups}"
84
85     vdir=${PWD}/${pldistro}-filesystems/${NAME}
86     rm -rf ${vdir}/*
87     install -d -m 755 ${vdir}
88
89     # Clone the base reference to the bootstrap fs
90     (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
91     rm -f ${vdir}/var/lib/rpm/__db*
92
93     # Install the system vserver specific packages
94     [ -n "$packages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $packages
95     [ -n "$groups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $groups
96
97     if [ -f "${vdir}/proc/cpuinfo" ] ; then
98         echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
99         umount ${vdir}/proc
100     fi
101
102     # optionally invoke a post processing script after packages from
103     # $pkgs have been installed
104     pkgsdir=$(dirname $pkgs)
105     pkgsname=$(basename $pkgs .pkgs)
106     postfile="${pkgsdir}/${pkgsname}.post"
107     [ -f $postfile ] && /bin/bash $postfile ${vdir} || :
108
109
110     # Create a copy of the ${NAME} bootstrap filesystem w/o the base
111     # bootstrap filesystem and make it smaller.  This is a three step
112     # process:
113
114     # step 1: clean out yum cache to reduce space requirements
115     yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
116
117     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
118     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
119     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
120     let headcount=$linecount-3
121     let tailcount=$headcount-1
122     # get rid of the last 3 lines of the rsync output
123     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
124     # get rid of the first line of the rsync output
125     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
126     # post process rsync output to get rid of symbolic link embellish output
127     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
128     rm -f ${vdir}.changes.*
129
130     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
131     install -d -m 755 ${vdir}-tmp/
132     rm -rf ${vdir}-tmp/*
133     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
134     rm -rf ${vdir}
135     rm -f  ${vdir}.changes
136     mv ${vdir}-tmp ${vdir}
137     
138     echo "--------STARTING tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
139     tar -cpjf ${pldistro}-filesystems/PlanetLab-Bootstrap-${NAME}.tar.bz2 -C ${vdir} .
140     echo "--------FINISHED tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
141     echo "--------DONE BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
142 done
143
144 # Build the base Bootstrap filesystem
145 # clean out yum cache to reduce space requirements
146 yum -c ${vref}/etc/yum.conf --installroot=${vref} -y clean all
147
148 echo "--------STARTING tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
149 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C ${vref} .
150 echo "--------FINISHED tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
151
152 exit 0