3 # Builds all reference image for vservers. To optimize for space it
4 # will only build a complete base vserver 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 # vserver reference image by an init script that is installed on the
11 # Mark Huang <mlhuang@cs.princeton.edu>
12 # Marc E. Fiuczynski <mef@cs.princeton.edu>
13 # Copyright (C) 2004-2007 The Trustees of Princeton University
16 PATH=/sbin:/bin:/usr/sbin:/usr/bin
18 # In both a normal CVS environment and a PlanetLab RPM
19 # build environment, all of our dependencies are checked out into
20 # directories at the same level as us.
21 if [ -d ../build ] ; then
25 echo "Error: Could not find $(cd .. && pwd -P)/build/"
31 # build.common comes from the build module
34 pl_process_fedora_options $@
38 # pldistro expected as $1
40 # The vserver reference name - this comes from spec's slicefamily
43 # Do not tolerate errors
46 # Path's to the vserver references images and stubs
47 vrefdir=$PWD/vservers/.vref
48 vref=${vrefdir}/${slicefamily}
49 # stubs are created in a subdir per slicefamily
50 vstubdir=$PWD/vservers/.vstub/${slicefamily}
52 # Make /vservers and default vserver reference image
53 install -d -m 755 ${vref}
54 # needed for pldistros that don't have any system vserver images
55 install -d -m 755 ${vstubdir}
57 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
58 # unless the installation is running inside the BootCD environment. We
59 # would like to pretend that we are.
62 # Populate image with vserver-reference packages
63 pl_root_makedevs ${vref}
64 # locate the packages and groups file
65 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} vserver.pkgs)
66 pl_root_mkfedora ${vref} ${pldistro} $pkgsfile
67 pl_root_tune_image ${vref}
69 systemvserver_count=$(ls ../build/config.${pldistro}/vserver-*.pkgs 2> /dev/null | wc -l)
70 [ $systemvserver_count -gt 0 ] && for systemvserver in $(ls ../build/config.${pldistro}/vserver-*.pkgs) ; do
71 NAME=$(basename $systemvserver .pkgs | sed -e s,vserver-,,)
73 echo "--------START BUILDING system vserver ${NAME}: $(date)"
75 # "Parse" out the packages and groups for yum
76 systempackages=$(pl_getPackages ${pl_DISTRO_NAME} $pldistro $systemvserver)
77 systemgroups=$(pl_getGroups ${pl_DISTRO_NAME} $pldistro $systemvserver)
79 vdir=${vstubdir}/${NAME}
81 install -d -m 755 ${vdir}
83 # Clone the base vserver reference to the system vserver reference
84 (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
85 rm -f ${vdir}/var/lib/rpm/__db*
87 # Communicate to the initialization script from which vref this stub was cloned
88 echo ${slicefamily} > ${vdir}.cloned
90 # Install the system vserver specific packages
91 [ -n "$systempackages" ] && yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y install $systempackages
92 for group_plus in $systemgroups; do
93 group=$(echo $group_plus | sed -e "s,+++, ,g")
94 yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y groupinstall "$group"
97 # search e.g. vserver-planetflow.post in config.<pldistro> or in config.planetlab otherwise
98 postfile=$(pl_locateDistroFile ../build/ ${pldistro} vserver-${NAME}.post || : )
100 [ -f $postfile ] && /bin/bash $postfile ${vdir} || :
102 # Create a copy of the system vserver w/o the vserver reference files and make it smaller.
103 # This is a three step process:
105 # step 1: clean out yum cache to reduce space requirements
106 yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y clean all
108 # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
109 rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
110 linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
111 let headcount=$linecount-3
112 let tailcount=$headcount-1
113 # get rid of the last 3 lines of the rsync output
114 head -${headcount} ${vdir}.changes > ${vdir}.changes.1
115 # get rid of the first line of the rsync output
116 tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
117 # post process rsync output to get rid of symbolic link embellish output
118 awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
119 rm -f ${vdir}.changes.*
121 # step 3: create the ${vdir} with just the list given in ${vdir}.changes
122 install -d -m 755 ${vdir}-tmp/
124 (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
126 rm -f ${vdir}.changes
127 mv ${vdir}-tmp ${vdir}
129 # cleanup yum remainings
130 rm -rf ${vdir}/build ${vdir}/longbuildroot
132 echo "--------DONE BUILDING system vserver ${NAME}: $(date)"
135 # search vserver.post in config.<pldistro> or in config.planetlab otherwise
136 postfile=$(pl_locateDistroFile ../build/ ${pldistro} vserver.post)
138 [ -f $postfile ] && /bin/bash $postfile ${vref} || :
141 [ -f ${vref}/etc/sudoers ] && echo -e "\nDefaults\tlogfile=/var/log/sudo\n" >> ${vref}/etc/sudoers
143 # cleanup yum remainings
144 rm -rf ${vref}/build ${vref}/longbuildroot