3 # Builds all reference image for slices. To optimize for space it
4 # will only build a complete base reference image and then
5 # builds "stub" images that are just contain the additional files
6 # and/or changes for a given reference image. This is done to shrink
7 # the RPM itself. These will be pieced back together with the base
8 # image by an init script that is installed on the node.
10 # Mark Huang <mlhuang@cs.princeton.edu>
11 # Marc E. Fiuczynski <mef@cs.princeton.edu>
12 # Copyright (C) 2004-2007 The Trustees of Princeton University
15 PATH=/sbin:/bin:/usr/sbin:/usr/bin
17 # In both a normal CVS environment and a PlanetLab RPM
18 # build environment, all of our dependencies are checked out into
19 # directories at the same level as us.
20 if [ -d ../build ] ; then
24 echo "Error: Could not find $(cd .. && pwd -P)/build/"
30 # build.common comes from the build module
33 pl_process_fedora_options $@
37 # pldistro expected as $1
39 # this comes from spec's slicefamily
42 # Do not tolerate errors
45 # Path's to the reference images and stubs
46 # This is inherited from util-vservers
47 vrefdir=$PWD/vservers/.vref
48 vref=${vrefdir}/${slicefamily}
49 # stubs are created in a subdir per slicefamily
50 vstubdir=$PWD/vservers/.vstub/${slicefamily}
53 install -d -m 755 ${vref}
54 install -d -m 755 ${vstubdir}
56 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
57 # unless the installation is running inside the BootCD environment. We
58 # would like to pretend that we are.
61 # Populate image with sliceimage packages
62 pl_root_makedevs ${vref}
63 # locate the packages and groups file
64 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} sliceimage.pkgs)
65 pl_root_mkfedora ${vref} ${pldistro} $pkgsfile
66 pl_root_tune_image ${vref}
68 systemslice_count=$(ls ../build/config.${pldistro}/sliceimage-*.pkgs 2> /dev/null | wc -l)
69 [ $systemslice_count -gt 0 ] && for systemslice in $(ls ../build/config.${pldistro}/sliceimage-*.pkgs) ; do
70 NAME=$(basename $systemslice .pkgs | sed -e s,sliceimage-,,)
72 echo "--------START BUILDING system sliceimage ${NAME}: $(date)"
74 # "Parse" out the packages and groups for yum
75 systempackages=$(pl_getPackages ${pl_DISTRO_NAME} $pldistro $systemslice)
76 systemgroups=$(pl_getGroups ${pl_DISTRO_NAME} $pldistro $systemslice)
78 vdir=${vstubdir}/${NAME}
80 install -d -m 755 ${vdir}
82 # Clone the base sliceimage reference to the system sliceimage reference
83 (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
84 rm -f ${vdir}/var/lib/rpm/__db*
86 # Communicate to the initialization script from which vref this stub was cloned
87 echo ${slicefamily} > ${vdir}.cloned
89 # Install the system sliceimage specific packages
90 [ -n "$systempackages" ] && yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y install $systempackages
91 for group_plus in $systemgroups; do
92 group=$(echo $group_plus | sed -e "s,+++, ,g")
93 yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y groupinstall "$group"
96 # search e.g. sliceimage-planetflow.post in config.<pldistro> or in config.planetlab otherwise
97 postfile=$(pl_locateDistroFile ../build/ ${pldistro} sliceimage-${NAME}.post || : )
99 [ -f $postfile ] && /bin/bash $postfile ${vdir} || :
101 # Create a copy of the system sliceimage w/o the sliceimage reference files and make it smaller.
102 # This is a three step process:
104 # step 1: clean out yum cache to reduce space requirements
105 yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y clean all
107 # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
108 rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
109 linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
110 let headcount=$linecount-3
111 let tailcount=$headcount-1
112 # get rid of the last 3 lines of the rsync output
113 head -${headcount} ${vdir}.changes > ${vdir}.changes.1
114 # get rid of the first line of the rsync output
115 tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
116 # post process rsync output to get rid of symbolic link embellish output
117 awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
118 rm -f ${vdir}.changes.*
120 # step 3: create the ${vdir} with just the list given in ${vdir}.changes
121 install -d -m 755 ${vdir}-tmp/
123 (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
125 rm -f ${vdir}.changes
126 mv ${vdir}-tmp ${vdir}
128 # cleanup yum remainings
129 rm -rf ${vdir}/build ${vdir}/longbuildroot
131 echo "--------DONE BUILDING system sliceimage ${NAME}: $(date)"
134 # search sliceimage.post in config.<pldistro> or in config.planetlab otherwise
135 postfile=$(pl_locateDistroFile ../build/ ${pldistro} sliceimage.post)
137 [ -f $postfile ] && /bin/bash $postfile ${vref} || :
140 [ -f ${vref}/etc/sudoers ] && echo -e "\nDefaults\tlogfile=/var/log/sudo\n" >> ${vref}/etc/sudoers
142 # cleanup yum remainings
143 rm -rf ${vref}/build ${vref}/longbuildroot