can yum install groups (use +++ for space) in bootstrapfs and vserver-reference
[bootstrapfs.git] / build.sh
1 #!/bin/bash
2 #
3 # Build bootstrapfs-*.tar.bz2, the reference image(s) for PlanetLab nodes.
4 #
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Marc E. Fiuczynski <mef@cs.princeton.edu>
7 # Copyright (C) 2005-2007 The Trustees of Princeton University
8 #
9 # $Id$
10 #
11
12 #
13 # This will build the bootstrafs-*.tar.bz2 images, which comprises
14 # the base root image on the node, then create the ${NAME} bootstrap image
15 # which is made up of just the additional files needed for a ${NAME} nodegroup 
16 # node.
17 #
18
19 PATH=/sbin:/bin:/usr/sbin:/usr/bin
20
21 # in the PlanetLab build environment, our dependencies are checked out 
22 # into 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 ../build in $(pwd)"
28     exit 1
29 fi
30
31 export PATH
32
33 . build.common
34
35 pl_process_fedora_options $@
36 shiftcount=$?
37 shift $shiftcount
38
39 # expecting fcdistro and pldistro on the command line
40 pldistro=$1; shift
41 fcdistro=${pl_DISTRO_NAME}
42
43 # Do not tolerate errors
44 set -e
45
46 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
47 # unless the installation is running inside the BootCD environment. We
48 # would like to pretend that we are.
49 export PL_BOOTCD=1
50
51 # Populate a minimal /dev and then the files for the base bootstrapfs content
52 vref=${PWD}/base
53 install -d -m 755 ${vref}
54 pl_root_makedevs $vref
55
56 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.pkgs)
57 echo "* Building Bootstrapfs for ${pldistro}: $(date)"
58 # -k = exclude kernel* packages
59 pl_root_mkfedora ${vref} ${pldistro} $pkgsfile
60
61 # optionally invoke a post processing script after packages from
62 # $pkgsfile have been installed
63 postfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.post || : )
64 [ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vref} || : ; }
65
66 displayed=""
67
68 # for distros that do not define bootstrapfs variants
69 pkgs_count=$(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs 2> /dev/null | wc -l)
70 [ $pkgs_count -gt 0 ] && for pkgs in $(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs); do
71     NAME=$(basename $pkgs .pkgs | sed -e s,bootstrapfs-,,)
72
73     [ -z "$displayed" ] && echo "* Handling ${plistro} bootstrapfs extensions"
74     displayed=true
75
76     extension_plain=bootstrapfs-${NAME}-${pl_DISTRO_ARCH}.tar
77     extension_name=bootstrapfs-${NAME}-${pl_DISTRO_ARCH}.tar.bz2
78
79     echo "* Start Building $extension_name: $(date)"
80
81     # "Parse" out the packages and groups for yum
82     packages=$(pl_getPackages $fcdistro $pldistro $pkgs)
83     groups=$(pl_getGroups $fcdistro $pldistro $pkgs)
84     echo "${NAME} has the following packages : ${packages}"
85     echo "${NAME} has the following groups : ${groups}"
86
87     vdir=${PWD}/${pldistro}-filesystems/${NAME}
88     rm -rf ${vdir}/*
89     install -d -m 755 ${vdir}
90
91     # Clone the base reference to the bootstrap fs
92     (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
93     rm -f ${vdir}/var/lib/rpm/__db*
94
95     # Install the system vserver specific packages
96     [ -n "$packages" ] && yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y install $packages
97     for group_plus in $groups; do
98         group=$(echo $group_plus | sed -e "s,+++, ,g")
99         yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y groupinstall "$group"
100     done
101
102
103     if [ -f "${vdir}/proc/cpuinfo" ] ; then
104         echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
105         umount ${vdir}/proc
106     fi
107
108     # optionally invoke a post processing script after packages from
109     # $pkgs have been installed
110     postfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs-${NAME}.post || : )
111     [ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vdir} || : ; }
112
113     # Create a copy of the ${NAME} bootstrap filesystem w/o the base
114     # bootstrap filesystem and make it smaller.  This is a three step
115     # process:
116
117     # step 1: clean out yum cache to reduce space requirements
118     yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y clean all
119
120     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
121     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
122     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
123     let headcount=$linecount-3
124     let tailcount=$headcount-1
125     # get rid of the last 3 lines of the rsync output
126     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
127     # get rid of the first line of the rsync output
128     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
129     # post process rsync output to get rid of symbolic link embellish output
130     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
131     rm -f ${vdir}.changes.*
132
133     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
134     install -d -m 755 ${vdir}-tmp/
135     rm -rf ${vdir}-tmp/*
136     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
137     rm -rf ${vdir}
138     rm -f  ${vdir}.changes
139     mv ${vdir}-tmp ${vdir}
140     
141     echo -n "* tar $extension_name s=$(date +%H-%M-%S)"
142     tar -cpf ${pldistro}-filesystems/$extension_plain -C ${vdir} .
143     echo -n " m=$(date +%H-%M-%S) "
144     bzip2 --compress --stdout ${pldistro}-filesystems/$extension_plain > ${pldistro}-filesystems/$extension_name
145     echo " e=$(date +%H-%M-%S) "
146 done
147
148 # Build the base Bootstrap filesystem
149 # clean out yum cache to reduce space requirements
150 yum -c ${vref}/etc/mkfedora-yum.conf --installroot=${vref} -y clean all
151
152 bootstrapfs_plain=bootstrapfs-${pldistro}-${pl_DISTRO_ARCH}.tar
153 bootstrapfs_name=bootstrapfs-${pldistro}-${pl_DISTRO_ARCH}.tar.bz2
154 echo -n "* tar $bootstrapfs_name s=$(date +%H-%M-%S)"
155 tar -cpf $bootstrapfs_plain -C ${vref} .
156 echo -n " m=$(date +%H-%M-%S) "
157 bzip2 --compress --stdout $bootstrapfs_plain > $bootstrapfs_name
158 echo " e=$(date +%H-%M-%S) "
159
160 exit 0