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 # Do not tolerate errors
43 # Path's to the vserver references images and stubs
44 vrefdir=$PWD/vservers/.vref
45 vstubdir=$PWD/vservers/.vstub
47 # XXX: The vserver reference name should be passed in as an argument
48 # rather than being hardcoded.
51 # Make /vservers and default vserver reference image
52 vref=${vrefdir}/${vrefname}
53 install -d -m 755 ${vref}
55 # "Parse" out the packages and groups for mkfedora
56 vrefpackages=$(grep "^package:.*" vserver-reference.lst | awk '{print $2}')
57 vrefgroups=$(grep "^group:.*" vserver-reference.lst | awk '{print $2}')
59 for package in ${vrefpackages} ; do options="$options -p $package"; done
60 for group in ${vrefgroups} ; do options="$options -g $group"; done
62 # Populate a minimal /dev in the reference image
65 # Populate image with vserver-reference packages
66 pl_setup_chroot ${vref} ${options}
68 for systemvserver in reference-vservers/*.lst ; do
69 NAME=$(basename $systemvserver .lst)
71 # "Parse" out the packages and groups for yum
72 systempackages=$(grep "^package:.*" $systemvserver | awk '{print $2}')
73 systemgroups=$(grep "^group:.*" $systemvserver | awk '{print $2}')
75 vdir=${vstubdir}/${NAME}
76 install -d -m 755 ${vdir}
78 # Clone the base vserver reference to the system vserver reference
79 # OPTIMIZATION: Consider using "cp -al" in the future
80 rsync -a ${vref}/ ${vdir}/
81 rm -f ${vdir}/var/lib/rpm/__db*
83 # Communicate to the initialization script from which vref this stub was cloned
84 echo ${vrefname} > ${vdir}.cloned
86 # Construct the excludes & includes patterns for rsync
87 (cd ${vdir} && find *) > ${vdir}.excludes
88 echo "var/lib/rpm/*" > ${vdir}.includes
90 # Install the system vserver specific packages
91 [ -n "$systempackages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $systempackages
92 [ -n "$systemgroups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $systemgroups
94 # Create a copy of the system vserver w/o the vserver reference files
96 rsync -a --include-from=${vdir}.includes --exclude-from=${vdir}.excludes ${vdir}/ ${vdir}-tmp/
98 rm -f ${vdir}.excludes ${vdir}.includes
99 mv ${vdir}-tmp ${vdir}