Second step towards multiarch myplc https://svn.planet-lab.org/ticket/214
[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: buildnode.sh,v 1.12.6.1 2007/08/30 20:09:20 mef Exp $
10 #
11
12
13 #
14 # This will build the bootstrafs-*.tar.bz2 images, which comprises
15 # the base root image on the node, then create the ${NAME} bootstrap image
16 # which is made up of just the additional files needed for a ${NAME} nodegroup 
17 # node.
18 #
19
20 PATH=/sbin:/bin:/usr/sbin:/usr/bin
21
22 # in the PlanetLab build environment, our dependencies are checked out 
23 # into directories at the same level as us.
24 if [ -d ../build ] ; then
25     PATH=$PATH:../build
26     srcdir=../
27 else
28     echo "Error: Could not find ../build in $(pwd)"
29     exit 1
30 fi
31
32 export PATH
33
34 . build.common
35
36 pl_process_fedora_options $@
37 shiftcount=$?
38 shift $shiftcount
39
40 # expecting fcdistro and pldistro on the command line
41 pldistro=$1; shift
42 fcdistro=${pl_DISTRO_NAME}
43
44 # Do not tolerate errors
45 set -e
46
47 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
48 # unless the installation is running inside the BootCD environment. We
49 # would like to pretend that we are.
50 export PL_BOOTCD=1
51
52 echo "+++++++++++++pkgsfile=$pkgsfile (and -k)"
53
54 # Populate a minimal /dev and then the files for the base bootstrapfs content
55 vref=${PWD}/base
56 install -d -m 755 ${vref}
57 pl_root_makedevs $vref
58
59 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.pkgs)
60 # -k = exclude kernel* packages
61 pl_root_mkfedora ${vref} ${pldistro} $pkgsfile
62
63 # optionally invoke a post processing script after packages from
64 # $pkgsfile have been installed
65 pkgsdir=$(dirname $pkgsfile)
66 pkgsname=$(basename $pkgsfile .pkgs)
67 postfile="${pkgsdir}/${pkgsname}.post"
68 [ -f $postfile ] && /bin/bash $postfile ${vref} || :
69
70 # for distros that do not define bootstrapfs variants
71 pkgs_count=$(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs 2> /dev/null | wc -l)
72 [ $pkgs_count -gt 0 ] && for pkgs in $(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs); do
73     NAME=$(basename $pkgs .pkgs | sed -e s,bootstrapfs-,,)
74
75     echo "--------START BUILDING bootstrapfs-${NAME}: $(date)"
76
77     # "Parse" out the packages and groups for yum
78     packages=$(pl_getPackages $fcdistro $pldistro $pkgs)
79     groups=$(pl_getGroups $fcdistro $pldistro $pkgs)
80     echo "${NAME} has the following packages : ${packages}"
81     echo "${NAME} has the following groups : ${groups}"
82
83     vdir=${PWD}/${pldistro}-filesystems/${NAME}
84     rm -rf ${vdir}/*
85     install -d -m 755 ${vdir}
86
87     # Clone the base reference to the bootstrap fs
88     (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
89     rm -f ${vdir}/var/lib/rpm/__db*
90
91     # Install the system vserver specific packages
92     [ -n "$packages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $packages
93     [ -n "$groups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $groups
94
95     if [ -f "${vdir}/proc/cpuinfo" ] ; then
96         echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
97         umount ${vdir}/proc
98     fi
99
100     # optionally invoke a post processing script after packages from
101     # $pkgs have been installed
102     pkgsdir=$(dirname $pkgs)
103     pkgsname=$(basename $pkgs .pkgs)
104     postfile="${pkgsdir}/${pkgsname}.post"
105     [ -f $postfile ] && /bin/bash $postfile ${vdir} || :
106
107
108     # Create a copy of the ${NAME} bootstrap filesystem w/o the base
109     # bootstrap filesystem and make it smaller.  This is a three step
110     # process:
111
112     # step 1: clean out yum cache to reduce space requirements
113     yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
114
115     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
116     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
117     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
118     let headcount=$linecount-3
119     let tailcount=$headcount-1
120     # get rid of the last 3 lines of the rsync output
121     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
122     # get rid of the first line of the rsync output
123     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
124     # post process rsync output to get rid of symbolic link embellish output
125     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
126     rm -f ${vdir}.changes.*
127
128     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
129     install -d -m 755 ${vdir}-tmp/
130     rm -rf ${vdir}-tmp/*
131     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
132     rm -rf ${vdir}
133     rm -f  ${vdir}.changes
134     mv ${vdir}-tmp ${vdir}
135     
136     echo "--------STARTING tar'ing bootstrapfs-${NAME}-${pl_DISTRO_ARCH}.tar.bz2: $(date)"
137     tar -cpjf ${pldistro}-filesystems/bootstrapfs-${NAME}-${pl_DISTRO_ARCH}.tar.bz2 -C ${vdir} .
138     echo "--------FINISHED tar'ing bootstrapfs-${NAME}-${pl_DISTRO_ARCH}.tar.bz2: $(date)"
139     echo "--------DONE BUILDING bootstrapfs-${NAME}-${pl_DISTRO_ARCH}: $(date)"
140 done
141
142 # Build the base Bootstrap filesystem
143 # clean out yum cache to reduce space requirements
144 yum -c ${vref}/etc/yum.conf --installroot=${vref} -y clean all
145
146 echo "--------STARTING tar'ing bootstrapfs-${pldistro}-${pl_DISTRO_ARCH}.tar.bz2: $(date)"
147 tar -cpjf bootstrapfs-${pldistro}-${pl_DISTRO_ARCH}.tar.bz2 -C ${vref} .
148 echo "--------FINISHED tar'ing bootstrapfs-${pldistro}-${pl_DISTRO_ARCH}.tar.bz2: $(date)"
149
150 exit 0