add site_admin account
[bootstrapfs.git] / build.sh
1 #!/bin/bash
2 #
3 # Build PlanetLab-Bootstrap.tar.bz2, the reference image for PlanetLab
4 # nodes.
5 #
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Marc E. Fiuczynski <mef@cs.princeton.edu>
8 # Copyright (C) 2005-2007 The Trustees of Princeton University
9 #
10 # $Id: buildnode.sh,v 1.12.6.1 2007/08/30 20:09:20 mef Exp $
11 #
12
13 PATH=/sbin:/bin:/usr/sbin:/usr/bin
14
15 # In both a normal CVS environment and a PlanetLab RPM
16 # build environment, all of our dependencies are checked out into
17 # directories at the same level as us.
18 if [ -d ../build ] ; then
19     PATH=$PATH:../build
20     srcdir=../
21 else
22     echo "Error: Could not find $(cd ../.. && pwd -P)/build/"
23     exit 1
24 fi
25
26 export PATH
27
28 . build.common
29
30 pl_process_fedora_options $@
31 shiftcount=$?
32 shift $shiftcount
33
34 # pldistro expected as $1 - defaults to planetlab
35 pldistro=planetlab
36 [ -n "$@" ] && pldistro=$1
37
38 # Do not tolerate errors
39 set -e
40
41 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
42 # unless the installation is running inside the BootCD environment. We
43 # would like to pretend that we are.
44 export PL_BOOTCD=1
45
46 echo "+++++++++++++pkgsfile=$pkgsfile (and -k)"
47
48 # Populate a minimal /dev and then the files for the base PlanetLab-Bootstrap content
49 vref=${PWD}/base
50 install -d -m 755 ${vref}
51 pl_root_makedevs $vref
52
53 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.pkgs)
54 # -k = exclude kernel* packages
55 pl_root_mkfedora -k -f $pkgsfile ${vref} 
56
57 for pkgs in ../build/config.${pldistro}/bootstrapfs-*.pkgs ; do
58     NAME=$(basename $pkgs .pkgs | sed -e s,bootstrapfs-,,)
59
60     echo "--------START BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
61
62     # "Parse" out the packages and groups for yum
63     packages=$(pl_getPackages ${pl_DISTRO_NAME} $pkgs)
64     groups=$(pl_getGroups ${pl_DISTRO_NAME} $pkgs)
65     echo "${NAME} has the following packages : ${packages}"
66     echo "${NAME} has the following groups : ${groups}"
67
68     vdir=${PWD}/${pldistro}-filesystems/${NAME}
69     rm -rf ${vdir}/*
70     install -d -m 755 ${vdir}
71
72     # Clone the base reference to the bootstrap fs
73     (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
74     rm -f ${vdir}/var/lib/rpm/__db*
75
76     # Install the system vserver specific packages
77     [ -n "$packages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $packages
78     [ -n "$groups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $groups
79
80     if [ -f "${vdir}/proc/cpuinfo" ] ; then
81         echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
82         umount ${vdir}/proc
83     fi
84
85     # Remove unneeded services
86     for service in util-vserver vprocunhide vservers-default; do
87         chroot ${vdir} /sbin/chkconfig $service off
88     done
89     
90     # Add site_admin account
91     chroot ${vdir} /usr/sbin/useradd -p "" -u 502 -m site_admin
92
93     # Create a copy of the ${NAME} bootstrap filesystem w/o the base
94     # bootstrap filesystem and make it smaller.  This is a three step
95     # process:
96
97     # step 1: clean out yum cache to reduce space requirements
98     yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
99
100     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
101     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
102     linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
103     let headcount=$linecount-3
104     let tailcount=$headcount-1
105     # get rid of the last 3 lines of the rsync output
106     head -${headcount} ${vdir}.changes > ${vdir}.changes.1
107     # get rid of the first line of the rsync output
108     tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
109     # post process rsync output to get rid of symbolic link embellish output
110     awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
111     rm -f ${vdir}.changes.*
112
113     # step 3: create the ${vdir} with just the list given in ${vdir}.changes 
114     install -d -m 755 ${vdir}-tmp/
115     rm -rf ${vdir}-tmp/*
116     (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
117     rm -rf ${vdir}
118     rm -f  ${vdir}.changes
119     mv ${vdir}-tmp ${vdir}
120
121     echo "--------STARTING tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
122     tar -cpjf ${pldistro}-filesystems/PlanetLab-Bootstrap-${NAME}.tar.bz2 -C ${vdir} .
123     echo "--------FINISHED tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
124     echo "--------DONE BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
125 done
126
127 # Build the base Bootstrap filesystem
128 # clean out yum cache to reduce space requirements
129 yum -c ${vref}/etc/yum.conf --installroot=${vdir} -y clean all
130 echo "--------STARTING tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
131 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C ${vref} .
132 echo "--------FINISHED tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
133
134 exit 0