using disablerepo with extras makes sense with fc <= 6 only
[sliceimage.git] / build.sh
1 #!/bin/bash
2 #
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
9 # node.
10 #
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
14 #
15 # $Id: build.sh,v 1.20 2007/09/06 20:41:23 faiyaza Exp $
16 #
17
18 PATH=/sbin:/bin:/usr/sbin:/usr/bin
19
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
24     PATH=$PATH:../build
25     srcdir=..
26 else
27     echo "Error: Could not find $(cd .. && pwd -P)/build/"
28     exit 1
29 fi
30
31 export PATH
32
33 # build.common comes from the build module
34 . build.common
35
36 pl_process_fedora_options $@
37 shiftcount=$?
38 shift $shiftcount
39
40 # Do not tolerate errors
41 set -e
42
43 # Path's to the vserver references images and stubs
44 vrefdir=$PWD/vservers/.vref
45 vstubdir=$PWD/vservers/.vstub
46
47 # XXX: The vserver reference name should be passed in as an argument
48 # rather than being hardcoded.
49 vrefname=default
50
51 # Make /vservers and default vserver reference image
52 vref=${vrefdir}/${vrefname}
53 install -d -m 755 ${vref}
54
55 # "Parse" out the packages and groups for mkfedora
56 lst="vserver-reference.lst"
57 options="$(pl_getPackagesOptions $lst) $(pl_getGroupsOptions $lst)"
58
59 # Populate a minimal /dev in the reference image
60 pl_makedevs ${vref}
61
62 # Populate image with vserver-reference packages
63 pl_setup_chroot ${vref} ${options}
64
65 for systemvserver in reference-vservers/*.lst ; do
66     NAME=$(basename $systemvserver .lst)
67
68     echo "--------START BUILDING system vserver ${NAME}: $(date)"
69
70     # "Parse" out the packages and groups for yum
71     systempackages=$(pl_getPackages $systemvserver)
72     systemgroups=$(pl_getGroups $systemvserver)
73
74     vdir=${vstubdir}/${NAME}
75     rm -rf ${vdir}/*
76     install -d -m 755 ${vdir}
77
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*
81
82     # Communicate to the initialization script from which vref this stub was cloned
83     echo ${vrefname} > ${vdir}.cloned
84
85     # Install the system vserver specific packages
86     # xxx - thierry -adding disablerepo for closing the build loop - should be solved some other way
87     if [ "$pl_DISTRO_RELEASE" -le 6 ] ; then
88         xxx=--disablerepo=extras
89     fi
90     [ -n "$systempackages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} $xxx -y install $systempackages
91     [ -n "$systemgroups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $systemgroups
92
93     # Create a copy of the system vserver w/o the vserver reference files and make it smaller. 
94     # This is a three step process:
95
96     # step 1: clean out yum cache to reduce space requirements
97     yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
98
99     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
100     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
101     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
102     let headcount=$linecount-3
103     let tailcount=$headcount-1
104     # get rid of the last 3 lines of the rsync output
105     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
106     # get rid of the first line of the rsync output
107     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
108     # post process rsync output to get rid of symbolic link embellish output
109     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
110     rm -f ${vdir}.changes.*
111
112     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
113     install -d -m 755 ${vdir}-tmp/
114     rm -rf ${vdir}-tmp/*
115     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
116     rm -rf ${vdir}
117     rm -f  ${vdir}.changes
118     mv ${vdir}-tmp ${vdir}
119     echo "--------DONE BUILDING system vserver ${NAME}: $(date)"
120 done
121
122 exit 0