- stop plc services before upgrading
[myplc.git] / build.sh
index 294d6a2..3b7a379 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -6,7 +6,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: build.sh,v 1.4 2006/03/29 03:36:53 mlhuang Exp $
+# $Id$
 #
 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
@@ -18,7 +18,7 @@ if [ -d ../build ] ; then
     PATH=$PATH:../build
     srcdir=..
 else
-    echo "Error: Could not find sources in either . or .."
+    echo "Error: Could not find $(cd .. && pwd -P)/build/"
     exit 1
 fi
 
@@ -31,9 +31,6 @@ config=plc_config.xml
 releasever=2
 basearch=i386
 
-# Data directory base
-usr_share=/usr/share
-
 # Initial size of the image
 size=1000000000
 
@@ -43,14 +40,13 @@ usage()
     echo "     -c file         PLC configuration file (default: $config)"
     echo "     -r release      Fedora release number (default: $releasever)"
     echo "     -a arch         Fedora architecture (default: $basearch)"
-    echo "     -d datadir      Data directory base (default: $usr_share)"
     echo "     -s size         Approximate size of the installation (default: $size)"
     echo "     -h              This message"
     exit 1
 }
 
 # Get options
-while getopts "c:r:a:d:s:h" opt ; do
+while getopts "c:r:a:s:h" opt ; do
     case $opt in
        c)
            config=$OPTARG
@@ -61,9 +57,6 @@ while getopts "c:r:a:d:s:h" opt ; do
        a)
            basearch=$OPTARG
            ;;
-       d)
-           usr_share=$OPTARG
-           ;;
        s)
            size=$OPTARG
            ;;
@@ -73,8 +66,11 @@ while getopts "c:r:a:d:s:h" opt ; do
     esac
 done
 
-root=fc$releasever
-data=data$releasever
+# Do not tolerate errors
+set -e
+
+root=root
+data=data
 
 if [ ! -f $root.img ] ; then
     bs=4096
@@ -85,7 +81,7 @@ fi
 
 mkdir -p $root $data
 mount -o loop $root.img $root
-trap "umount $root; exit 1" ERR
+trap "umount $root" ERR
 
 #
 # Build
@@ -99,6 +95,9 @@ done < <(./plc-config --packages $config)
 # Install base system
 mkfedora -v -r $releasever -a $basearch $packages $root
 
+# Disable all services in reference image
+chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
+
 # FC2 minilogd starts up during shutdown and makes unmounting
 # impossible. Just get rid of it.
 rm -f $root/sbin/minilogd
@@ -118,8 +117,9 @@ chroot $root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py in
 install -D -m 755 plc-config $root/usr/bin/plc-config
 install -D -m 755 api-config $root/usr/bin/api-config
 
-# Install init script
-echo "* Installing initscript"
+# Install initscripts
+echo "* Installing initscripts"
+find plc.d | cpio -p -d -u $root/etc/
 install -D -m 755 guest.init $root/etc/init.d/plc
 chroot $root sh -c 'chkconfig --add plc; chkconfig plc on'
 
@@ -146,27 +146,6 @@ rsync -a \
     --exclude=geni --exclude=PDN --exclude=Talks \
     $srcdir/plc_www/ $root/var/www/html/
 
-# Install node RPMs
-if [ -n "$RPM_BUILD_DIR" ] ; then
-    echo "* Installing node RPMs"
-    RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
-    mkdir -p $root/var/www/html/install-rpms/planetlab
-    # Exclude ourself (e.g., if rebuilding), the bootcd and
-    # bootmanager builds, and debuginfo RPMs.
-    rsync -a \
-       --exclude='myplc-*' \
-       --exclude='bootcd-*' --exclude='bootmanager-*' \
-       --exclude='*-debuginfo-*' \
-       $(find $RPM_RPMS_DIR -type f -and -name '*.rpm') \
-       $root/var/www/html/install-rpms/planetlab/
-    if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
-       install -D -m 644 $RPM_RPMS_DIR/yumgroups.xml \
-           $root/var/www/html/install-rpms/planetlab/yumgroups.xml
-    fi
-    yum-arch $root/var/www/html/install-rpms/planetlab || :
-    createrepo $root/var/www/html/install-rpms/planetlab || :
-fi
-
 # XXX Build imprintable BootCD and BootManager images.
 
 # Install configuration file
@@ -181,6 +160,7 @@ datadirs=(
 /var/www/html/boot
 /var/www/html/download
 /var/www/html/generated
+/var/www/html/install-rpms
 /var/www/html/xml
 )
 
@@ -239,11 +219,35 @@ fi
 
 # Write sysconfig
 cat >plc.sysconfig <<EOF
-PLC_ROOT=$usr_share/plc/$root
-PLC_DATA=$usr_share/plc/$data
+PLC_ROOT=/plc/$root
+PLC_DATA=/plc/$data
 #PLC_OPTIONS="-v"
 EOF
 
+# Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
+# tarball already contains all of the node RPMs pre-installed. Only
+# updates or optional packages should be placed in this directory.
+if [ -n "$RPM_BUILD_DIR" ] ; then
+    echo "* Initializing node RPMs directory"
+    RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
+    mkdir -p $data/var/www/html/install-rpms/planetlab
+    if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
+       install -D -m 644 $RPM_RPMS_DIR/yumgroups.xml \
+           $data/var/www/html/install-rpms/planetlab/yumgroups.xml
+    fi
+    # yum-2.0.x
+    if [ -x /usr/bin/yum-arch ] ; then
+       yum-arch $data/var/www/html/install-rpms/planetlab
+    fi
+    # yum-2.4.x
+    if [ -x /usr/bin/createrepo ] ; then
+       if [ -f $data/var/www/html/install-rpms/planetlab/yumgroups.xml ] ; then
+           groupfile="-g yumgroups.xml"
+       fi
+       createrepo $groupfile $data/var/www/html/install-rpms/planetlab
+    fi
+fi
+
 # Bootstrap the system for quicker startup (and to populate the
 # PlanetLabConf tables from PLC, which may not be accessible
 # later). The bootstrap.xml configuration overlay configures the web
@@ -265,6 +269,11 @@ RETVAL=$?
 # Restore default configuration before shutting down
 install -D -m 644 $config $data/etc/planetlab/plc_config.xml
 
+# Remove ISO and USB images, which take up >100MB but only take a
+# couple of seconds to generate at first boot.
+rm -f $data/var/www/html/download/*.{iso,usb}
+install -D -m 644 $config $data/etc/planetlab/plc_config.xml
+
 ./host.init stop
 RETVAL=$(($RETVAL+$?))