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.3 2006/03/28 21:30:48 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/
149 # XXX Build imprintable BootCD and BootManager images.
151 # Install configuration file
152 echo "* Installing configuration file"
153 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
155 # Move "data" directories out of the installation
159 /var/www/html/alpina-logs
161 /var/www/html/download
162 /var/www/html/generated
163 /var/www/html/install-rpms
167 echo "* Moving data directories out of the installation"
169 for datadir in "${datadirs[@]}" ; do
170 mkdir -p ${data}$datadir
171 if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
172 (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
174 rm -rf $root/$datadir
175 mkdir -p $(dirname $root/$datadir)
176 ln -nsf /data$datadir $root/$datadir
179 # Shrink to 100 MB free space
182 df = os.statvfs('$root')
183 target = 100 * 1024 * 1024 / df.f_bsize
184 if df.f_bavail > target:
185 print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024
192 if [ -n "$kb" ] ; then
193 # Setup loopback association. Newer versions of losetup have a -f
194 # option which finds an unused loopback device, but we must
195 # support FC2 for now.
196 # dev_loop=$(losetup -f)
197 for i in `seq 1 7` ; do
198 if ! grep -q "^/dev/loop$i" /proc/mounts ; then
199 dev_loop="/dev/loop$i"
203 losetup $dev_loop $root.img
204 trap "losetup -d $dev_loop" ERR
206 # Resize the filesystem
207 echo "* Checking filesystem"
208 e2fsck -a -f $dev_loop
209 echo "* Shrinking filesystem"
210 resize2fs $dev_loop ${kb}K
212 # Tear down loopback association
216 # Truncate the image file
217 perl -e "truncate '$root.img', $kb*1024"
221 cat >plc.sysconfig <<EOF
222 PLC_ROOT=$usr_share/plc/$root
223 PLC_DATA=$usr_share/plc/$data
228 if [ -n "$RPM_BUILD_DIR" ] ; then
229 echo "* Installing node RPMs"
230 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
231 mkdir -p $data/var/www/html/install-rpms/planetlab
232 # Exclude ourself (e.g., if rebuilding), the bootcd and
233 # bootmanager builds, and debuginfo RPMs.
235 --exclude='myplc-*' \
236 --exclude='bootcd-*' --exclude='bootmanager-*' \
237 --exclude='*-debuginfo-*' \
238 $(find $RPM_RPMS_DIR -type f -and -name '*.rpm') \
239 $data/var/www/html/install-rpms/planetlab/
240 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
241 install -D -m 644 $RPM_RPMS_DIR/yumgroups.xml \
242 $data/var/www/html/install-rpms/planetlab/yumgroups.xml
244 yum-arch $data/var/www/html/install-rpms/planetlab || :
245 createrepo $data/var/www/html/install-rpms/planetlab || :
248 # Bootstrap the system for quicker startup (and to populate the
249 # PlanetLabConf tables from PLC, which may not be accessible
250 # later). The bootstrap.xml configuration overlay configures the web
251 # server to run on an alternate port (in case the build machine itself
252 # is running a web server on port 80). Start everything up to
253 # bootstrap the database, then shut it back down again immediately.
254 echo "* Bootstrapping installation"
256 ./plc-config --save $data/etc/planetlab/plc_config.xml bootstrap.xml
258 # Otherwise, host.init will try to read /etc/sysconfig/plc
259 export PLC_ROOT=$PWD/$root
260 export PLC_DATA=$PWD/$data
261 #export PLC_OPTIONS="-v"
266 # Restore default configuration before shutting down
267 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
270 RETVAL=$(($RETVAL+$?))