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 a normal CVS environment, the requisite CVS modules (including
15 # build/) are located at the same level we are. In a PlanetLab RPM
16 # build environment (see the RPM spec file), they are checked out into
18 if [ -d ./build ] ; then
21 elif [ -d ../build ] ; then
25 echo "Error: Could not find sources in either . or .."
31 # PLC configuration file
34 # Release and architecture to install
41 # Initial size of the image
46 echo "Usage: build.sh [OPTION]..."
47 echo " -c file PLC configuration file (default: $config)"
48 echo " -r release Fedora release number (default: $releasever)"
49 echo " -a arch Fedora architecture (default: $basearch)"
50 echo " -d datadir Data directory base (default: $usr_share)"
51 echo " -s size Approximate size of the installation (default: $size)"
52 echo " -h This message"
57 while getopts "c:r:a:d:s:h" opt ; do
83 if [ ! -f $root.img ] ; then
85 count=$(($size / 4096))
86 dd bs=$bs count=$count if=/dev/zero of=$root.img
87 mkfs.ext3 -j -F $root.img
91 mount -o loop $root.img $root
92 trap "umount $root; exit 1" ERR
99 while read package ; do
100 packages="$packages -p $package"
101 done < <(./plc-config --packages $config)
103 # Install base system
104 mkfedora -v -r $releasever -a $basearch $packages $root
106 # FC2 minilogd starts up during shutdown and makes unmounting
107 # impossible. Just get rid of it.
108 rm -f $root/sbin/minilogd
109 ln -nsf /bin/true $root/sbin/minilogd
112 make -C $srcdir/pl_db
118 # Install configuration scripts
119 install -D -m 755 plc_config.py $root/tmp/plc_config.py
120 chroot $root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
121 install -D -m 755 plc-config $root/usr/bin/plc-config
122 install -D -m 755 api-config $root/usr/bin/api-config
124 # Install init script
125 install -D -m 755 guest.init $root/etc/init.d/plc
126 chroot $root sh -c 'chkconfig --add plc; chkconfig plc on'
128 # Install DB schema and API code
129 mkdir -p $root/usr/share
130 rsync -a $srcdir/pl_db $srcdir/plc_api $root/usr/share/
132 # Install web scripts
133 mkdir -p $root/usr/bin
135 plc/scripts/gen-sites-xml.py \
136 plc/scripts/gen-slices-xml-05.py \
137 plc/scripts/gen-static-content.py \
141 mkdir -p $root/var/www/html
142 rsync -a $srcdir/plc_www/ $root/var/www/html/
144 # Install configuration file
145 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
147 # Move "data" directories out of the installation
151 /var/www/html/alpina-logs
153 /var/www/html/download
154 /var/www/html/generated
155 /var/www/html/install-rpms
160 for datadir in "${datadirs[@]}" ; do
161 mkdir -p ${data}$datadir
162 if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
163 (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
165 rm -rf $root/$datadir
166 mkdir -p $(dirname $root/$datadir)
167 ln -nsf /data$datadir $root/$datadir
170 # Shrink to 100 MB free space
173 df = os.statvfs('$root')
174 target = 100 * 1024 * 1024 / df.f_bsize
175 if df.f_bavail > target:
176 print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024
183 if [ -n "$kb" ] ; then
184 # Setup loopback association. Newer versions of losetup have a -f
185 # option which finds an unused loopback device, but we must
186 # support FC2 for now.
187 # dev_loop=$(losetup -f)
188 for i in `seq 1 7` ; do
189 if ! grep -q "^/dev/loop$i" /proc/mounts ; then
190 dev_loop="/dev/loop$i"
194 losetup $dev_loop $root.img
195 trap "losetup -d $dev_loop" ERR
197 # Resize the filesystem
199 resize2fs $dev_loop ${kb}K
201 # Tear down loopback association
205 # Truncate the image file
206 perl -e "truncate '$root.img', $kb*1024"
210 cat >plc.sysconfig <<EOF
211 PLC_ROOT=$usr_share/plc/$root
212 PLC_DATA=$usr_share/plc/$data