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 $(cd .. && pwd -P)/build/"
27 # PLC configuration file
30 # Release and architecture to install
34 # Initial size of the image
39 echo "Usage: build.sh [OPTION]..."
40 echo " -c file PLC configuration file (default: $config)"
41 echo " -r release Fedora release number (default: $releasever)"
42 echo " -a arch Fedora architecture (default: $basearch)"
43 echo " -s size Approximate size of the installation (default: $size)"
44 echo " -h This message"
49 while getopts "c:r:a:s:h" opt ; do
69 # Do not tolerate errors
75 if [ ! -f $root.img ] ; then
77 count=$(($size / 4096))
78 dd bs=$bs count=$count if=/dev/zero of=$root.img
79 mkfs.ext3 -j -F $root.img
83 mount -o loop $root.img $root
84 trap "umount $root" ERR
91 while read package ; do
92 packages="$packages -p $package"
93 done < <(./plc-config --packages $config)
96 mkfedora -v -r $releasever -a $basearch $packages $root
98 # Disable all services in reference image
99 chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
101 # FC2 minilogd starts up during shutdown and makes unmounting
102 # impossible. Just get rid of it.
103 rm -f $root/sbin/minilogd
104 ln -nsf /bin/true $root/sbin/minilogd
107 make -C $srcdir/pl_db
113 # Install configuration scripts
114 echo "* Installing configuration scripts"
115 install -D -m 755 plc_config.py $root/tmp/plc_config.py
116 chroot $root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
117 install -D -m 755 plc-config $root/usr/bin/plc-config
118 install -D -m 755 api-config $root/usr/bin/api-config
120 # Install init script
121 echo "* Installing initscript"
122 install -D -m 755 guest.init $root/etc/init.d/plc
123 chroot $root sh -c 'chkconfig --add plc; chkconfig plc on'
125 # Install DB schema and API code
126 echo "* Installing DB schema and API code"
127 mkdir -p $root/usr/share
128 rsync -a $srcdir/pl_db $srcdir/plc_api $root/usr/share/
130 # Install web scripts
131 echo "* Installing web scripts"
132 mkdir -p $root/usr/bin
134 $srcdir/plc/scripts/gen-sites-xml.py \
135 $srcdir/plc/scripts/gen-slices-xml-05.py \
136 $srcdir/plc/scripts/gen-static-content.py \
140 echo "* Installing web pages"
141 mkdir -p $root/var/www/html
142 # Exclude old cruft, unrelated GENI pages, and official documents
144 --exclude='*2002' --exclude='*2003' \
145 --exclude=geni --exclude=PDN --exclude=Talks \
146 $srcdir/plc_www/ $root/var/www/html/
148 # XXX Build imprintable BootCD and BootManager images.
150 # Install configuration file
151 echo "* Installing configuration file"
152 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
154 # Move "data" directories out of the installation
158 /var/www/html/alpina-logs
160 /var/www/html/download
161 /var/www/html/generated
162 /var/www/html/install-rpms
166 echo "* Moving data directories out of the installation"
168 for datadir in "${datadirs[@]}" ; do
169 mkdir -p ${data}$datadir
170 if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
171 (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
173 rm -rf $root/$datadir
174 mkdir -p $(dirname $root/$datadir)
175 ln -nsf /data$datadir $root/$datadir
178 # Shrink to 100 MB free space
181 df = os.statvfs('$root')
182 target = 100 * 1024 * 1024 / df.f_bsize
183 if df.f_bavail > target:
184 print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024
191 if [ -n "$kb" ] ; then
192 # Setup loopback association. Newer versions of losetup have a -f
193 # option which finds an unused loopback device, but we must
194 # support FC2 for now.
195 # dev_loop=$(losetup -f)
196 for i in `seq 1 7` ; do
197 if ! grep -q "^/dev/loop$i" /proc/mounts ; then
198 dev_loop="/dev/loop$i"
202 losetup $dev_loop $root.img
203 trap "losetup -d $dev_loop" ERR
205 # Resize the filesystem
206 echo "* Checking filesystem"
207 e2fsck -a -f $dev_loop
208 echo "* Shrinking filesystem"
209 resize2fs $dev_loop ${kb}K
211 # Tear down loopback association
215 # Truncate the image file
216 perl -e "truncate '$root.img', $kb*1024"
220 cat >plc.sysconfig <<EOF
226 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
227 # tarball already contains all of the node RPMs pre-installed. Only
228 # updates or optional packages should be placed in this directory.
229 if [ -n "$RPM_BUILD_DIR" ] ; then
230 echo "* Initializing node RPMs directory"
231 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
232 mkdir -p $data/var/www/html/install-rpms/planetlab
233 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
234 install -D -m 644 $RPM_RPMS_DIR/yumgroups.xml \
235 $data/var/www/html/install-rpms/planetlab/yumgroups.xml
238 if [ -x /usr/bin/yum-arch ] ; then
239 yum-arch $data/var/www/html/install-rpms/planetlab
242 if [ -x /usr/bin/createrepo ] ; then
243 if [ -f $data/var/www/html/install-rpms/planetlab/yumgroups.xml ] ; then
244 groupfile="-g yumgroups.xml"
246 createrepo $groupfile $data/var/www/html/install-rpms/planetlab
250 # Bootstrap the system for quicker startup (and to populate the
251 # PlanetLabConf tables from PLC, which may not be accessible
252 # later). The bootstrap.xml configuration overlay configures the web
253 # server to run on an alternate port (in case the build machine itself
254 # is running a web server on port 80). Start everything up to
255 # bootstrap the database, then shut it back down again immediately.
256 echo "* Bootstrapping installation"
258 ./plc-config --save $data/etc/planetlab/plc_config.xml bootstrap.xml
260 # Otherwise, host.init will try to read /etc/sysconfig/plc
261 export PLC_ROOT=$PWD/$root
262 export PLC_DATA=$PWD/$data
263 #export PLC_OPTIONS="-v"
268 # Restore default configuration before shutting down
269 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
272 RETVAL=$(($RETVAL+$?))