fix using the wrong variable names, update comments, and put in some debugging echo...
[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 # Do not tolerate errors
35 set -e
36
37 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
38 # unless the installation is running inside the BootCD environment. We
39 # would like to pretend that we are.
40 export PL_BOOTCD=1
41
42 # "Parse" out the packages and groups into the options passed to mkfedora
43 # -k = exclude kernel* packages
44 options="-k"
45 packages=$(pl_getPackages base.lst)
46 groups=$(pl_getGroups base.lst)
47 for package in ${packages} ; do  options="$options -p $package"; done
48 for group in ${groups} ; do options="$options -g $group"; done
49
50 echo "+++++++++++++OPTIONS = ${options}"
51
52 # Populate a minimal /dev and then the files for the base PlanetLab-Bootstrap content
53 vref=${PWD}/base
54 install -d -m 755 ${vref}
55 pl_mkfedora ${vref} ${options}
56
57 for bootstrapfs in bootstrap-filesystems/*.lst ; do
58     NAME=$(basename $bootstrapfs .lst)
59
60     echo "--------START BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
61
62     # "Parse" out the packages and groups for yum
63     packages=$(pl_getPackages $bootstrapfs)
64     groups=$(pl_getGroups $bootstrapfs)
65     echo "${NAME} has the following packages and groups: ${packages} ${groups}"
66
67     vdir=${PWD}/bootstrap-filesystems/${NAME}
68     rm -rf ${vdir}/*
69     install -d -m 755 ${vdir}
70
71     # Clone the base reference to the bootstrap fs
72     (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
73     rm -f ${vdir}/var/lib/rpm/__db*
74
75     # Install the system vserver specific packages
76     [ -n "$packages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $packages
77     [ -n "$groups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $groups
78
79     # Create a copy of the ${NAME} bootstrap filesystem w/o the base
80     # bootstrap filesystem and make it smaller.  This is a three step
81     # process:
82
83     # step 1: clean out yum cache to reduce space requirements
84     yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
85
86     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
87     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
88     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
89     let headcount=$linecount-3
90     let tailcount=$headcount-1
91     # get rid of the last 3 lines of the rsync output
92     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
93     # get rid of the first line of the rsync output
94     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
95     # post process rsync output to get rid of symbolic link embellish output
96     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
97     rm -f ${vdir}.changes.*
98
99     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
100     install -d -m 755 ${vdir}-tmp/
101     rm -rf ${vdir}-tmp/*
102     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
103     rm -rf ${vdir}
104     rm -f  ${vdir}.changes
105     mv ${vdir}-tmp ${vdir}
106
107     echo "--------STARTING tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
108     tar -cpjf bootstrap-filesystems/PlanetLab-Bootstrap-${NAME}.tar.bz2 -C ${vdir} .
109     echo "--------FINISHED tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
110     echo "--------DONE BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
111 done
112
113 # Build the base Bootstrap filesystem
114 echo "--------STARTING tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
115 # clean out yum cache to reduce space requirements
116 yum -c ${vref}/etc/yum.conf --installroot=${vdir} -y clean all
117 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C ${vref} .
118 echo "--------FINISHED tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
119
120 exit 0