3 # Builds a Fedora based PLC image. You should be able to run this
4 # script multiple times without a problem.
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
9 # $Id: build.sh,v 1.4 2006/03/29 03:36:53 mlhuang Exp $
12 PATH=/sbin:/bin:/usr/sbin:/usr/bin
14 # In both a normal CVS environment and a PlanetLab RPM
15 # build environment, all of our dependencies are checked out into
16 # directories at the same level as us.
17 if [ -d ../build ] ; then
21 echo "Error: Could not find sources in either . or .."
27 # PLC configuration file
30 # Release and architecture to install
37 # Initial size of the image
42 echo "Usage: build.sh [OPTION]..."
43 echo " -c file PLC configuration file (default: $config)"
44 echo " -r release Fedora release number (default: $releasever)"
45 echo " -a arch Fedora architecture (default: $basearch)"
46 echo " -d datadir Data directory base (default: $usr_share)"
47 echo " -s size Approximate size of the installation (default: $size)"
48 echo " -h This message"
53 while getopts "c:r:a:d:s:h" opt ; do
79 if [ ! -f $root.img ] ; then
81 count=$(($size / 4096))
82 dd bs=$bs count=$count if=/dev/zero of=$root.img
83 mkfs.ext3 -j -F $root.img
87 mount -o loop $root.img $root
88 trap "umount $root; exit 1" ERR
95 while read package ; do
96 packages="$packages -p $package"
97 done < <(./plc-config --packages $config)
100 mkfedora -v -r $releasever -a $basearch $packages $root
102 # FC2 minilogd starts up during shutdown and makes unmounting
103 # impossible. Just get rid of it.
104 rm -f $root/sbin/minilogd
105 ln -nsf /bin/true $root/sbin/minilogd
108 make -C $srcdir/pl_db
114 # Install configuration scripts
115 echo "* Installing configuration scripts"
116 install -D -m 755 plc_config.py $root/tmp/plc_config.py
117 chroot $root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
118 install -D -m 755 plc-config $root/usr/bin/plc-config
119 install -D -m 755 api-config $root/usr/bin/api-config
121 # Install init script
122 echo "* Installing initscript"
123 install -D -m 755 guest.init $root/etc/init.d/plc
124 chroot $root sh -c 'chkconfig --add plc; chkconfig plc on'
126 # Install DB schema and API code
127 echo "* Installing DB schema and API code"
128 mkdir -p $root/usr/share
129 rsync -a $srcdir/pl_db $srcdir/plc_api $root/usr/share/
131 # Install web scripts
132 echo "* Installing web scripts"
133 mkdir -p $root/usr/bin
135 $srcdir/plc/scripts/gen-sites-xml.py \
136 $srcdir/plc/scripts/gen-slices-xml-05.py \
137 $srcdir/plc/scripts/gen-static-content.py \
141 echo "* Installing web pages"
142 mkdir -p $root/var/www/html
143 # Exclude old cruft, unrelated GENI pages, and official documents
145 --exclude='*2002' --exclude='*2003' \
146 --exclude=geni --exclude=PDN --exclude=Talks \
147 $srcdir/plc_www/ $root/var/www/html/
150 if [ -n "$RPM_BUILD_DIR" ] ; then
151 echo "* Installing node RPMs"
152 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
153 mkdir -p $root/var/www/html/install-rpms/planetlab
154 # Exclude ourself (e.g., if rebuilding), the bootcd and
155 # bootmanager builds, and debuginfo RPMs.
157 --exclude='myplc-*' \
158 --exclude='bootcd-*' --exclude='bootmanager-*' \
159 --exclude='*-debuginfo-*' \
160 $(find $RPM_RPMS_DIR -type f -and -name '*.rpm') \
161 $root/var/www/html/install-rpms/planetlab/
162 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
163 install -D -m 644 $RPM_RPMS_DIR/yumgroups.xml \
164 $root/var/www/html/install-rpms/planetlab/yumgroups.xml
166 yum-arch $root/var/www/html/install-rpms/planetlab || :
167 createrepo $root/var/www/html/install-rpms/planetlab || :
170 # XXX Build imprintable BootCD and BootManager images.
172 # Install configuration file
173 echo "* Installing configuration file"
174 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
176 # Move "data" directories out of the installation
180 /var/www/html/alpina-logs
182 /var/www/html/download
183 /var/www/html/generated
187 echo "* Moving data directories out of the installation"
189 for datadir in "${datadirs[@]}" ; do
190 mkdir -p ${data}$datadir
191 if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
192 (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
194 rm -rf $root/$datadir
195 mkdir -p $(dirname $root/$datadir)
196 ln -nsf /data$datadir $root/$datadir
199 # Shrink to 100 MB free space
202 df = os.statvfs('$root')
203 target = 100 * 1024 * 1024 / df.f_bsize
204 if df.f_bavail > target:
205 print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024
212 if [ -n "$kb" ] ; then
213 # Setup loopback association. Newer versions of losetup have a -f
214 # option which finds an unused loopback device, but we must
215 # support FC2 for now.
216 # dev_loop=$(losetup -f)
217 for i in `seq 1 7` ; do
218 if ! grep -q "^/dev/loop$i" /proc/mounts ; then
219 dev_loop="/dev/loop$i"
223 losetup $dev_loop $root.img
224 trap "losetup -d $dev_loop" ERR
226 # Resize the filesystem
227 echo "* Checking filesystem"
228 e2fsck -a -f $dev_loop
229 echo "* Shrinking filesystem"
230 resize2fs $dev_loop ${kb}K
232 # Tear down loopback association
236 # Truncate the image file
237 perl -e "truncate '$root.img', $kb*1024"
241 cat >plc.sysconfig <<EOF
242 PLC_ROOT=$usr_share/plc/$root
243 PLC_DATA=$usr_share/plc/$data
247 # Bootstrap the system for quicker startup (and to populate the
248 # PlanetLabConf tables from PLC, which may not be accessible
249 # later). The bootstrap.xml configuration overlay configures the web
250 # server to run on an alternate port (in case the build machine itself
251 # is running a web server on port 80). Start everything up to
252 # bootstrap the database, then shut it back down again immediately.
253 echo "* Bootstrapping installation"
255 ./plc-config --save $data/etc/planetlab/plc_config.xml bootstrap.xml
257 # Otherwise, host.init will try to read /etc/sysconfig/plc
258 export PLC_ROOT=$PWD/$root
259 export PLC_DATA=$PWD/$data
260 #export PLC_OPTIONS="-v"
265 # Restore default configuration before shutting down
266 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
269 RETVAL=$(($RETVAL+$?))