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
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
76 # Do not tolerate errors
82 if [ ! -f $root.img ] ; then
84 count=$(($size / 4096))
85 dd bs=$bs count=$count if=/dev/zero of=$root.img
86 mkfs.ext3 -j -F $root.img
90 mount -o loop $root.img $root
91 trap "umount $root" ERR
98 while read package ; do
99 packages="$packages -p $package"
100 done < <(./plc-config --packages $config)
102 # Install base system
103 mkfedora -v -r $releasever -a $basearch $packages $root
105 # Disable all services in reference image
106 chroot $vroot sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
108 # FC2 minilogd starts up during shutdown and makes unmounting
109 # impossible. Just get rid of it.
110 rm -f $root/sbin/minilogd
111 ln -nsf /bin/true $root/sbin/minilogd
114 make -C $srcdir/pl_db
120 # Install configuration scripts
121 echo "* Installing configuration scripts"
122 install -D -m 755 plc_config.py $root/tmp/plc_config.py
123 chroot $root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
124 install -D -m 755 plc-config $root/usr/bin/plc-config
125 install -D -m 755 api-config $root/usr/bin/api-config
127 # Install init script
128 echo "* Installing initscript"
129 install -D -m 755 guest.init $root/etc/init.d/plc
130 chroot $root sh -c 'chkconfig --add plc; chkconfig plc on'
132 # Install DB schema and API code
133 echo "* Installing DB schema and API code"
134 mkdir -p $root/usr/share
135 rsync -a $srcdir/pl_db $srcdir/plc_api $root/usr/share/
137 # Install web scripts
138 echo "* Installing web scripts"
139 mkdir -p $root/usr/bin
141 $srcdir/plc/scripts/gen-sites-xml.py \
142 $srcdir/plc/scripts/gen-slices-xml-05.py \
143 $srcdir/plc/scripts/gen-static-content.py \
147 echo "* Installing web pages"
148 mkdir -p $root/var/www/html
149 # Exclude old cruft, unrelated GENI pages, and official documents
151 --exclude='*2002' --exclude='*2003' \
152 --exclude=geni --exclude=PDN --exclude=Talks \
153 $srcdir/plc_www/ $root/var/www/html/
155 # XXX Build imprintable BootCD and BootManager images.
157 # Install configuration file
158 echo "* Installing configuration file"
159 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
161 # Move "data" directories out of the installation
165 /var/www/html/alpina-logs
167 /var/www/html/download
168 /var/www/html/generated
169 /var/www/html/install-rpms
173 echo "* Moving data directories out of the installation"
175 for datadir in "${datadirs[@]}" ; do
176 mkdir -p ${data}$datadir
177 if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
178 (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
180 rm -rf $root/$datadir
181 mkdir -p $(dirname $root/$datadir)
182 ln -nsf /data$datadir $root/$datadir
185 # Shrink to 100 MB free space
188 df = os.statvfs('$root')
189 target = 100 * 1024 * 1024 / df.f_bsize
190 if df.f_bavail > target:
191 print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024
198 if [ -n "$kb" ] ; then
199 # Setup loopback association. Newer versions of losetup have a -f
200 # option which finds an unused loopback device, but we must
201 # support FC2 for now.
202 # dev_loop=$(losetup -f)
203 for i in `seq 1 7` ; do
204 if ! grep -q "^/dev/loop$i" /proc/mounts ; then
205 dev_loop="/dev/loop$i"
209 losetup $dev_loop $root.img
210 trap "losetup -d $dev_loop" ERR
212 # Resize the filesystem
213 echo "* Checking filesystem"
214 e2fsck -a -f $dev_loop
215 echo "* Shrinking filesystem"
216 resize2fs $dev_loop ${kb}K
218 # Tear down loopback association
222 # Truncate the image file
223 perl -e "truncate '$root.img', $kb*1024"
227 cat >plc.sysconfig <<EOF
228 PLC_ROOT=$usr_share/plc/$root
229 PLC_DATA=$usr_share/plc/$data
234 if [ -n "$RPM_BUILD_DIR" ] ; then
235 echo "* Installing node RPMs"
236 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
237 mkdir -p $data/var/www/html/install-rpms/planetlab
238 # Exclude ourself (e.g., if rebuilding), the bootcd and
239 # bootmanager builds, and debuginfo RPMs.
241 --exclude='myplc-*' \
242 --exclude='bootcd-*' --exclude='bootmanager-*' \
243 --exclude='*-debuginfo-*' \
244 $(find $RPM_RPMS_DIR -type f -and -name '*.rpm') \
245 $data/var/www/html/install-rpms/planetlab/
246 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
247 install -D -m 644 $RPM_RPMS_DIR/yumgroups.xml \
248 $data/var/www/html/install-rpms/planetlab/yumgroups.xml
251 if [ -x /usr/bin/yum-arch ] ; then
252 yum-arch $data/var/www/html/install-rpms/planetlab
255 if [ -x /usr/bin/createrepo ] ; then
256 if [ -f $data/var/www/html/install-rpms/planetlab/yumgroups.xml ] ; then
257 groupfile="-g yumgroups.xml"
259 createrepo $groupfile $data/var/www/html/install-rpms/planetlab
263 # Bootstrap the system for quicker startup (and to populate the
264 # PlanetLabConf tables from PLC, which may not be accessible
265 # later). The bootstrap.xml configuration overlay configures the web
266 # server to run on an alternate port (in case the build machine itself
267 # is running a web server on port 80). Start everything up to
268 # bootstrap the database, then shut it back down again immediately.
269 echo "* Bootstrapping installation"
271 ./plc-config --save $data/etc/planetlab/plc_config.xml bootstrap.xml
273 # Otherwise, host.init will try to read /etc/sysconfig/plc
274 export PLC_ROOT=$PWD/$root
275 export PLC_DATA=$PWD/$data
276 #export PLC_OPTIONS="-v"
281 # Restore default configuration before shutting down
282 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
285 RETVAL=$(($RETVAL+$?))