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
15 # $Id: build.sh,v 1.20 2007/09/06 20:41:23 faiyaza Exp $
18 PATH=/sbin:/bin:/usr/sbin:/usr/bin
20 # In both a normal CVS environment and a PlanetLab RPM
21 # build environment, all of our dependencies are checked out into
22 # directories at the same level as us.
23 if [ -d ../build ] ; then
27 echo "Error: Could not find $(cd .. && pwd -P)/build/"
33 # build.common comes from the build module
36 pl_process_fedora_options $@
40 # pldistro expected as $1 - defaults to planetlab
42 [ -n "$@" ] && pldistro=$1
44 # Do not tolerate errors
47 # Path's to the vserver references images and stubs
48 vrefdir=$PWD/vservers/.vref
49 vstubdir=$PWD/vservers/.vstub
51 # XXX: The vserver reference name should be passed in as an argument
52 # rather than being hardcoded.
55 # Make /vservers and default vserver reference image
56 vref=${vrefdir}/${vrefname}
57 install -d -m 755 ${vref}
59 # locate the packages and groups file
60 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} vserver.pkgs)
62 # Populate image with vserver-reference packages
63 pl_root_setup_chroot ${vref} -k -f $pkgsfile
65 for systemvserver in ../build/config.${pldistro}/vserver-*.pkgs ; do
66 NAME=$(basename $systemvserver .pkgs | sed -e s,vserver-,,)
68 echo "--------START BUILDING system vserver ${NAME}: $(date)"
70 # "Parse" out the packages and groups for yum
71 systempackages=$(pl_getPackages ${pl_DISTRO_NAME} $systemvserver)
72 systemgroups=$(pl_getGroups ${pl_DISTRO_NAME} $systemvserver)
74 vdir=${vstubdir}/${NAME}
76 install -d -m 755 ${vdir}
78 # Clone the base vserver reference to the system vserver reference
79 (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
80 rm -f ${vdir}/var/lib/rpm/__db*
82 # Communicate to the initialization script from which vref this stub was cloned
83 echo ${vrefname} > ${vdir}.cloned
85 # Install the system vserver specific packages
86 [ -n "$systempackages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $systempackages
87 [ -n "$systemgroups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $systemgroups
89 # Create a copy of the system vserver w/o the vserver reference files and make it smaller.
90 # This is a three step process:
92 # step 1: clean out yum cache to reduce space requirements
93 yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
95 # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
96 rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
97 linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
98 let headcount=$linecount-3
99 let tailcount=$headcount-1
100 # get rid of the last 3 lines of the rsync output
101 head -${headcount} ${vdir}.changes > ${vdir}.changes.1
102 # get rid of the first line of the rsync output
103 tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
104 # post process rsync output to get rid of symbolic link embellish output
105 awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
106 rm -f ${vdir}.changes.*
108 # step 3: create the ${vdir} with just the list given in ${vdir}.changes
109 install -d -m 755 ${vdir}-tmp/
111 (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
113 rm -f ${vdir}.changes
114 mv ${vdir}-tmp ${vdir}
115 echo "--------DONE BUILDING system vserver ${NAME}: $(date)"