- split build.sh into two pieces: build_devel.sh, which builds
authorMark Huang <mlhuang@cs.princeton.edu>
Mon, 17 Jul 2006 21:31:31 +0000 (21:31 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Mon, 17 Jul 2006 21:31:31 +0000 (21:31 +0000)
  myplc-devel, and build.sh, which builds myplc itself (optionally
  inside of the myplc-devel environment just built)
- add plc_devel_config.xml, the configuration for myplc-devel

build.functions [new file with mode: 0644]
build.sh
build_devel.sh [new file with mode: 0755]
myplc.spec
plc_devel_config.xml [new file with mode: 0644]

diff --git a/build.functions b/build.functions
new file mode 100644 (file)
index 0000000..8281801
--- /dev/null
@@ -0,0 +1,151 @@
+# -*-Shell-script-*-
+#
+# Common functions for MyPLC build scripts (build_devel.sh and
+# build.sh)
+#
+# Mark Huang <mlhuang@cs.princeton.edu>
+# Copyright (C) 2006 The Trustees of Princeton University
+#
+# $Id: functions,v 1.6 2006/07/10 21:05:37 mlhuang Exp $
+#
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+# In both a normal CVS environment and a PlanetLab RPM
+# build environment, all of our dependencies are checked out into
+# directories at the same level as us.
+if [ -d ../build ] ; then
+    PATH=$PATH:../build
+    srcdir=..
+else
+    echo "Error: Could not find $(cd .. && pwd -P)/build/"
+    exit 1
+fi
+
+export PATH
+
+# Release and architecture to install
+PLC_DEVEL_FEDORA_RELEASE=4
+PLC_DEVEL_FEDORA_ARCH=i386
+
+# Fedora Core mirror from which to install filesystems
+PLC_DEVEL_FEDORA_URL=file:///usr/share/mirrors/fedora
+
+# Build myplc inside myplc-devel
+PLC_DEVEL_BOOTSTRAP=true
+
+# We may be running inside a myplc-devel environment, which can
+# override these defaults. Specifically, whether to build myplc inside
+# myplc-devel (PLC_DEVEL_BOOTSTRAP).
+if [ -f /etc/planetlab/plc_config ] ; then
+    . /etc/planetlab/plc_config
+fi
+
+usage()
+{
+    echo "Usage: build.sh [OPTION]..."
+    echo "     -l url          Fedora mirror location (default: $PLC_DEVEL_FEDORA_URL)"
+    echo "     -r release      Fedora release number (default: $PLC_DEVEL_FEDORA_RELEASE)"
+    echo "     -a arch         Fedora architecture (default: $PLC_DEVEL_FEDORA_ARCH)"
+    echo "     -h              This message"
+    exit 1
+}
+
+# Get options
+while getopts "l:r:a:h" opt ; do
+    case $opt in
+       l)
+           PLC_DEVEL_FEDORA_URL=$OPTARG
+           ;;
+       r)
+           PLC_DEVEL_FEDORA_RELEASE=$OPTARG
+           ;;
+       a)
+           PLC_DEVEL_FEDORA_ARCH=$OPTARG
+           ;;
+       h|*)
+           usage
+           ;;
+    esac
+done
+
+# Do not tolerate errors
+set -e
+
+# Be verbose
+set -x
+
+# Make a basic chroot at the specified location given the specified
+# configuration.
+make_chroot() {
+    root=$1
+    config=$2
+
+    # Get group list
+    groups=
+    while read group ; do
+       groups="$groups -g \"$group\""
+    done < <(./plc-config --groups $config)
+
+    # Get package list
+    packages=
+    while read package ; do
+       packages="$packages -p \"$package\""
+    done < <(./plc-config --packages $config)
+
+    # Install base system
+    eval mkfedora -v -l $PLC_DEVEL_FEDORA_URL -r $PLC_DEVEL_FEDORA_RELEASE -a $PLC_DEVEL_FEDORA_ARCH $packages $groups $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
+    ln -nsf /bin/true $root/sbin/minilogd
+}
+
+# Move specified directories out of the chroot and into a "data"
+# directory that will be bind mounted on /data inside the chroot.
+move_datadirs() {
+    root=$1
+    data=$2
+    shift 2
+
+    mkdir -p $root/data
+    for datadir in "$@" ; do
+       mkdir -p ${data}$datadir
+       if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
+           (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
+       fi
+       rm -rf $root/$datadir
+       mkdir -p $(dirname $root/$datadir)
+       ln -nsf /data$datadir $root/$datadir
+    done
+}
+
+# Make loopback filesystem from specified location
+make_image() {
+    root=$1
+    image=$2
+
+    # Leave about 100 MB free space and allow for about 20% inode overhead
+    bytes=$((($(du -sb $root | cut -f1) + 100000000) * 120 / 100))
+    bs=4096
+    blocks=$(($bytes / $bs))
+    dd bs=$bs count=$blocks if=/dev/zero of=$image
+    mkfs.ext3 -b $bs -j -F $image
+
+    # Temporarily mount it
+    tmp=$(mktemp -d tmp.XXXXXX)
+    mount -o loop $image $tmp
+    trap "umount $tmp; rmdir $tmp" ERR INT
+
+    # Move files to it
+    (cd $root && tar cpf - .) | (cd $tmp && tar xpf -)
+
+    # Unmount it
+    umount $tmp
+    rmdir $tmp
+    trap - ERR INT
+}
index 6d3733b..35cecab 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,7 +1,15 @@
 #!/bin/bash
 #
-# Builds a Fedora based PLC image. You should be able to run this
-# script multiple times without a problem.
+# Builds MyPLC, either inside the MyPLC development environment in
+# devel/root (if PLC_DEVEL_BOOTSTRAP is true), or in the current host
+# environment (may be itself a MyPLC development environment or a
+# Fedora Core 4 environment with the appropriate development packages
+# installed).
+#
+# root.img (loopback image)
+# root/ (mount point)
+# data/ (various data files)
+# data/etc/planetlab/ (configuration files)
 #
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 # $Id$
 #
 
-PATH=/sbin:/bin:/usr/sbin:/usr/bin
-
-# In both a normal CVS environment and a PlanetLab RPM
-# build environment, all of our dependencies are checked out into
-# directories at the same level as us.
-if [ -d ../build ] ; then
-    PATH=$PATH:../build
-    srcdir=..
-else
-    echo "Error: Could not find $(cd .. && pwd -P)/build/"
-    exit 1
-fi
-
-export PATH
-
-# PLC configuration file
-config=plc_config.xml
+. build.functions
 
-# Release and architecture to install
-releasever=4
-basearch=i386
+#
+# Build myplc inside myplc-devel. Infinite recursion is avoided only
+# if PLC_DEVEL_BOOTSTRAP is false in the default configuration file.
+#
 
-# Initial size of the image
-size=1000000000
+if [ "$PLC_DEVEL_BOOTSTRAP" = "true" ] ; then
+    # So that we don't pollute the actual myplc-devel image, we use
+    # the directory that was used to build the image instead of the
+    # image itself, and mount everything by hand.
+    mount -o bind,rw devel/data devel/root/data
+    mount -t proc none devel/root/proc
+
+    # If we used a local mirror, bind mount it into the chroot so that
+    # we can use it again.
+    if [ "${PLC_DEVEL_FEDORA_URL:0:7}" = "file://" ] ; then
+       mkdir -p devel/root/usr/share/mirrors/fedora
+       mount -o bind,ro ${PLC_DEVEL_FEDORA_URL#file://} devel/root/usr/share/mirrors/fedora
+    fi
 
-usage()
-{
-    echo "Usage: build.sh [OPTION]..."
-    echo "     -c file         PLC configuration file (default: $config)"
-    echo "     -r release      Fedora release number (default: $releasever)"
-    echo "     -a arch         Fedora architecture (default: $basearch)"
-    echo "     -s size         Approximate size of the installation (default: $size)"
-    echo "     -h              This message"
-    exit 1
-}
+    # Clean up before exiting if anything goes wrong
+    trap "umount $PWD/devel/root/data;
+          umount $PWD/devel/root/proc;
+          umount $PWD/devel/root/usr/share/mirrors/fedora" ERR INT
+
+    # Build myplc inside myplc-devel. Make sure PLC_DEVEL_BOOTSTRAP is
+    # false to avoid infinite recursion.
+    chroot devel/root sh -s <<EOF
+set -x
+service plc start
+plc-config --category=plc_devel --variable=bootstrap --value="false" --save
+service plc reload
+cd /
+cvs -d /cvs checkout build
+make -C /build myplc
+EOF
 
-# Get options
-while getopts "c:r:a:s:h" opt ; do
-    case $opt in
-       c)
-           config=$OPTARG
-           ;;
-       r)
-           releasever=$OPTARG
-           ;;
-       a)
-           basearch=$OPTARG
-           ;;
-       s)
-           size=$OPTARG
-           ;;
-       h|*)
-           usage
-           ;;
-    esac
-done
+    # Yoink the image that was just built
+    mv devel/data/build/BUILD/myplc-*/myplc/root{,.img} devel/data/build/BUILD/myplc-*/myplc/data .
 
-# Do not tolerate errors
-set -e
+    # Clean up
+    umount devel/root/data
+    umount devel/root/proc
+    umount devel/root/usr/share/mirrors/fedora || :
 
-root=root
-data=data
+    # Could leave it around, but it does consume a lot of disk space
+    # rm -rf devel/data/build
+    # mkdir -p devel/data/build
 
-if [ ! -f $root.img ] ; then
-    bs=4096
-    count=$(($size / 4096))
-    dd bs=$bs count=$count if=/dev/zero of=$root.img
-    mkfs.ext3 -j -F $root.img
+    # No need to continue
+    exit 0
 fi
 
-mkdir -p $root $data
-mount -o loop $root.img $root
-trap "umount $root" ERR
-
 #
-# Build
+# Build myplc in the host environment. This section is executed if
+# PLC_DEVEL_BOOTSTRAP is false.
 #
 
-# Get package list
-while read package ; do
-    packages="$packages -p $package"
-done < <(./plc-config --packages $config)
-
-# Install base system
-mkfedora -v -r $releasever -a $basearch -k $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
-ln -nsf /bin/true $root/sbin/minilogd
+echo "* myplc: Installing base filesystem"
+mkdir -p root data
+make_chroot root plc_config.xml
 
 # Build schema
+echo "* myplc: Building database schema"
 make -C $srcdir/pl_db
 
-#
-# Install
-#
-
 # Install configuration scripts
-echo "* Installing configuration scripts"
-install -D -m 755 plc_config.py $root/tmp/plc_config.py
-chroot $root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
-install -D -m 755 plc-config $root/usr/bin/plc-config
-install -D -m 755 api-config $root/usr/bin/api-config
-install -D -m 755 db-config $root/usr/bin/db-config
-install -D -m 755 dns-config $root/usr/bin/dns-config
-
-# Install OpenSSL configuration
-install -D -m 644 openssl.cnf $root/etc/planetlab/ssl/openssl.cnf
+echo "* myplc: Installing configuration scripts"
+install -D -m 755 plc_config.py root/tmp/plc_config.py
+chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
+install -D -m 755 plc-config root/usr/bin/plc-config
+install -D -m 755 api-config root/usr/bin/api-config
+install -D -m 755 db-config root/usr/bin/db-config
+install -D -m 755 dns-config root/usr/bin/dns-config
 
 # 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'
+echo "* myplc: 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'
 
 # Install DB schema and API code
-echo "* Installing DB schema and API code"
-mkdir -p $root/usr/share
-rsync -a $srcdir/pl_db $srcdir/plc_api $root/usr/share/
+echo "* myplc: Installing DB schema and API code"
+mkdir -p root/usr/share
+rsync -a $srcdir/pl_db $srcdir/plc_api root/usr/share/
 
 # Install web scripts
-echo "* Installing web scripts"
-mkdir -p $root/usr/bin
+echo "* myplc: Installing web scripts"
+mkdir -p root/usr/bin
 install -m 755 \
     $srcdir/plc/scripts/gen-sites-xml.py \
     $srcdir/plc/scripts/gen-slices-xml-05.py \
     $srcdir/plc/scripts/gen-static-content.py \
-    $root/usr/bin/
+    root/usr/bin/
 
 # Install web pages
-echo "* Installing web pages"
-mkdir -p $root/var/www/html
+echo "* myplc: Installing web pages"
+mkdir -p root/var/www/html
 # Exclude old cruft, unrelated GENI pages, and official documents
 rsync -a \
     --exclude='*2002' --exclude='*2003' \
     --exclude=geni --exclude=PDN --exclude=Talks \
-    $srcdir/plc_www/ $root/var/www/html/
+    $srcdir/plc_www/ root/var/www/html/
 
 # Install configuration file
-echo "* Installing configuration file"
-install -D -m 444 $config $data/etc/planetlab/default_config.xml
-install -D -m 444 plc_config.dtd $data/etc/planetlab/plc_config.dtd
+echo "* myplc: Installing configuration file"
+install -D -m 444 $config data/etc/planetlab/default_config.xml
+install -D -m 444 plc_config.dtd data/etc/planetlab/plc_config.dtd
 
 # Move "data" directories out of the installation
 datadirs=(
@@ -168,117 +139,34 @@ datadirs=(
 /var/www/html/xml
 )
 
-echo "* Moving data directories out of the installation"
-mkdir -p $root/data
-for datadir in "${datadirs[@]}" ; do
-    mkdir -p ${data}$datadir
-    if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
-       (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
-    fi
-    rm -rf $root/$datadir
-    mkdir -p $(dirname $root/$datadir)
-    ln -nsf /data$datadir $root/$datadir
-done
-
-# Shrink to 100 MB free space
-kb=$(python <<EOF
-import os
-df = os.statvfs('$root')
-target = 100 * 1024 * 1024 / df.f_bsize
-if df.f_bavail > target:
-    print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024
-EOF
-)
-
-umount $root
-trap - ERR
-
-if [ -n "$kb" ] ; then
-    # Setup loopback association. Newer versions of losetup have a -f
-    # option which finds an unused loopback device, but we must
-    # support FC2 for now.
-    # dev_loop=$(losetup -f)
-    for i in `seq 1 7` ; do
-       if ! grep -q "^/dev/loop$i" /proc/mounts ; then
-           dev_loop="/dev/loop$i"
-           break
-       fi
-    done
-    losetup $dev_loop $root.img
-    trap "losetup -d $dev_loop" ERR
-
-    # Resize the filesystem
-    echo "* Checking filesystem"
-    e2fsck -a -f $dev_loop
-    echo "* Shrinking filesystem"
-    resize2fs $dev_loop ${kb}K
-
-    # Tear down loopback association
-    losetup -d $dev_loop
-    trap - ERR
-
-    # Truncate the image file
-    perl -e "truncate '$root.img', $kb*1024"
-fi
-
-# Write sysconfig
-cat >plc.sysconfig <<EOF
-PLC_ROOT=/plc/$root
-PLC_DATA=/plc/$data
-#PLC_OPTIONS="-v"
-EOF
+move_datadirs root data "${datadirs[@]}"
 
 # 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"
+    echo "* myplc: Initializing node RPMs directory"
     RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
-    mkdir -p $data/var/www/html/install-rpms/planetlab
+    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
+           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
+       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
+       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
+       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
-# server to run on an alternate port (in case the build machine itself
-# is running a web server on port 80). Start everything up to
-# bootstrap the database, then shut it back down again immediately.
-echo "* Bootstrapping installation"
-
-install -D -m 644 bootstrap.xml $data/etc/planetlab/configs/bootstrap.xml
-
-# Otherwise, host.init will try to read /etc/sysconfig/plc
-export PLC_ROOT=$PWD/$root
-export PLC_DATA=$PWD/$data
-#export PLC_OPTIONS="-v"
-
-./host.init start
-RETVAL=$?
-
-# 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}
-
-./host.init stop
-RETVAL=$(($RETVAL+$?))
-
-# Restore default configuration
-rm -f $data/etc/planetlab/configs/bootstrap.xml
-install -D -m 444 $config $data/etc/planetlab/plc_config.xml
+# Make image out of directory
+echo "* myplc: Building loopback image"
+make_image root root.img
 
-exit $RETVAL
+exit 0
diff --git a/build_devel.sh b/build_devel.sh
new file mode 100755 (executable)
index 0000000..77893b3
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/bash
+#
+# Build a complete MyPLC development environment. Requires PlanetLab
+# source code to be exported into directories at the same level as we
+# are (i.e., ..).
+#
+# devel/root.img (loopback image)
+# devel/root/ (mount point)
+# devel/data/ (various data files)
+# devel/data/cvs/ (local CVS repository)
+# devel/data/build/ (build area)
+# devel/data/etc/planetlab/ (configuration)
+#
+# Mark Huang <mlhuang@cs.princeton.edu>
+# Copyright (C) 2006 The Trustees of Princeton University
+#
+# $Id$
+#
+
+. build.functions
+
+echo "* myplc-devel: Installing base filesystem"
+mkdir -p devel/root
+make_chroot devel/root plc_devel_config.xml
+
+# Import everything (including ourself) into a private CVS tree
+echo "* myplc-devel: Building CVS repository"
+cvsroot=$PWD/devel/data/cvs
+mkdir -p $cvsroot
+cvs -d $cvsroot init
+
+myplc=$(basename $PWD)
+pushd ..
+for dir in * ; do
+    if [ ! -d $cvsroot/$dir ] ; then
+       pushd $dir
+       if [ "$dir" = "$myplc" ] ; then
+           # Ignore generated files
+           ignore="-I ! -I devel -I root -I root.img -I data" 
+       else
+           ignore="-I !"
+       fi
+       date=$(date +%Y-%m-%d)
+       cvs -d $cvsroot import -m "Initial import" -ko $ignore $dir planetlab planetlab-$date
+       popd
+    fi
+done
+popd
+
+# Install configuration file
+echo "* myplc-devel: Installing configuration file"
+install -D -m 444 plc_devel_config.xml devel/data/etc/planetlab/default_config.xml
+install -D -m 444 plc_config.dtd devel/data/etc/planetlab/plc_config.dtd
+
+# Install configuration scripts
+echo "* myplc-devel: Installing configuration scripts"
+install -D -m 755 plc_config.py devel/root/tmp/plc_config.py
+chroot devel/root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
+install -D -m 755 plc-config devel/root/usr/bin/plc-config
+
+# Install initscripts
+echo "* myplc-devel: Installing initscripts"
+find plc.d/functions | cpio -p -d -u devel/root/etc/
+install -D -m 755 guest.init devel/root/etc/init.d/plc
+chroot devel/root sh -c 'chkconfig --add plc; chkconfig plc on'
+
+# Move "data" directories out of the installation
+echo "* myplc-devel: Moving data directories out of the installation"
+move_datadirs devel/root devel/data \
+    /etc/planetlab /build /cvs
+
+# Make image out of directory
+echo "* myplc-devel: Building loopback image"
+make_image devel/root devel/root.img
+
+exit 0
index 0a6a188..29a8960 100644 (file)
@@ -6,7 +6,7 @@ URL: http://cvs.planet-lab.org/cvs/myplc
 Summary: PlanetLab Central (PLC) Portable Installation
 Name: myplc
 Version: 0.5
-Release: 1%{?pldistro:.%{pldistro}}%{?date:.%{date}}
+Release: 2%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 License: PlanetLab
 Group: Applications/Systems
 Source0: %{name}-%{version}.tar.gz
@@ -23,12 +23,24 @@ through a graphical interface. All PLC services are started up and
 shut down through a single System V init script installed in the host
 system.
 
+%package devel
+Summary: PlanetLab Central (PLC) Development Environment
+Group: Development/Tools
+AutoReqProv: no
+
+%description devel
+This package install a complete PlanetLab development environment
+contained within a chroot jail. The default installation consists of a
+local CVS repository bootstrapped with a snapshot of all PlanetLab
+source code, and all the tools necessary to compile it.
+
 %prep
 %setup -q
 
 %build
 pushd myplc
-./build.sh
+#./build_devel.sh
+#./build.sh
 popd
 
 %install
@@ -36,6 +48,10 @@ rm -rf $RPM_BUILD_ROOT
 
 pushd myplc
 
+#
+# myplc
+#
+
 # Install host startup script and configuration file
 install -D -m 755 host.init $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/plc
 install -D -m 644 plc.sysconfig $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/plc
@@ -51,6 +67,21 @@ install -D -m 644 root.img $RPM_BUILD_ROOT/plc/root.img
 # Install data directory
 find data | cpio -p -d -u $RPM_BUILD_ROOT/plc/
 
+#
+# myplc-devel
+#
+
+# Install host startup script and configuration file
+install -D -m 755 host.init $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/plc-devel
+install -D -m 644 plc-devel.sysconfig $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/plc-devel
+
+# Install root filesystem
+install -d -m 755 $RPM_BUILD_ROOT/plc/devel/root
+install -D -m 644 devel/root.img $RPM_BUILD_ROOT/plc/devel/root.img
+
+# Install data directory
+find devel/data | cpio -p -d -u $RPM_BUILD_ROOT/plc/
+
 popd
 
 %clean
@@ -69,7 +100,32 @@ fi
 
 %pre
 if [ -x %{_sysconfdir}/init.d/plc ] ; then
-    service plc stop
+    %{_sysconfdir}/init.d/plc stop
+fi
+
+# Old versions of myplc used to ship with a bootstrapped database and
+# /etc/planetlab directory. Including generated files in the manifest
+# was dangerous; if /plc/data/var/lib/pgsql/data/base/1/16676 changed
+# names from one RPM build to another, it would be rpmsaved and thus
+# effectively deleted. Now we do not include these files in the
+# manifest. However, to avoid deleting these files in the process of
+# upgrading from one of these old versions of myplc, we must back up
+# the database and /etc/planetlab and restore them after the old
+# version has been uninstalled in %triggerpostun.
+
+# 0 = install, 1 = upgrade
+if [ $1 -gt 0 ] ; then
+    for dir in /var/lib/pgsql/data /etc/planetlab ; do
+       if [ -d /plc/data/$dir ] ; then
+           mv /plc/data/$dir /plc/data/$dir.rpmsave
+       fi
+    done
+
+    # Except for the default configuration file and DTD, which really
+    # should be considered for upgrade.
+    mkdir -m 755 -p /plc/data/etc/planetlab
+    mv /plc/data/etc/planetlab.rpmsave/{default_config.xml,plc_config.dtd} \
+       /plc/data/etc/planetlab/ || :
 fi
 
 %post
@@ -78,6 +134,22 @@ if [ -x /sbin/chkconfig ] ; then
     /sbin/chkconfig plc on
 fi
 
+# Force a regeneration to take into account new variables
+touch /plc/data/etc/planetlab/default_config.xml
+
+%triggerpostun -- %{name}
+# 0 = erase, 1 = upgrade
+if [ $1 -gt 0 ] ; then
+    for dir in /var/lib/pgsql/data /etc/planetlab ; do
+       if [ -d /plc/data/$dir.rpmsave -a -d /plc/data/$dir ] ; then
+           if tar -C /plc/data/$dir.rpmsave -cpf - . | \
+              tar -C /plc/data/$dir -xpf - ; then
+               rm -rf /plc/data/$dir.rpmsave
+           fi
+       fi
+    done
+fi    
+
 %preun
 # 0 = erase, 1 = upgrade
 if [ $1 -eq 0 ] ; then
@@ -88,6 +160,46 @@ if [ $1 -eq 0 ] ; then
     fi
 fi
 
+%pre devel
+if [ -x %{_sysconfdir}/init.d/plc-devel ] ; then
+    %{_sysconfdir}/init.d/plc-devel stop
+fi
+
+# 0 = install, 1 = upgrade
+if [ $1 -gt 0 ] ; then
+    # Never overwrite /cvs
+    if [ -d /plc/devel/data/cvs ] ; then
+       echo "Preserving /plc/devel/data/cvs"
+       mv /plc/devel/data/cvs /plc/devel/data/cvs.rpmsave
+    fi
+fi
+
+%post devel
+if [ -x /sbin/chkconfig ] ; then
+    /sbin/chkconfig --add plc-devel
+    /sbin/chkconfig plc-devel on
+fi
+
+%triggerpostun -- %{name}
+# 0 = erase, 1 = upgrade
+if [ $1 -gt 0 ] ; then
+    if [ -d /plc/devel/data/cvs.rpmsave ] ; then
+       echo "Restoring /plc/devel/data/cvs"
+       mv /plc/devel/data/cvs /plc/devel/data/cvs.%{version}-%{release}
+       mv /plc/devel/data/cvs.rpmsave /plc/devel/data/cvs
+    fi
+fi    
+
+%preun devel
+# 0 = erase, 1 = upgrade
+if [ $1 -eq 0 ] ; then
+    %{_sysconfdir}/init.d/plc-devel stop
+    if [ -x /sbin/chkconfig ] ; then
+        /sbin/chkconfig plc-devel off
+       /sbin/chkconfig --del plc-devel
+    fi
+fi
+
 %files
 %defattr(-,root,root,-)
 # Host startup script and configuration file
@@ -105,7 +217,40 @@ fi
 %dir /plc/data
 %config(noreplace) /plc/data/*
 
+%files devel
+%defattr(-,root,root,-)
+# Host startup script and configuration file
+%{_sysconfdir}/init.d/plc-devel
+%{_sysconfdir}/sysconfig/plc-devel
+
+# Root filesystem
+/plc/devel/root.img
+/plc/devel/root
+
+# Data directory
+%dir /plc/devel/data
+%config(noreplace) /plc/devel/data/*
+
 %changelog
+* Thu Jul 13 2006 Mark Huang <mlhuang@CS.Princeton.EDU> - 0.4-2, 0.5-2
+- MyPLC 0.4 RC2.
+- Build development environment (myplc-devel). Add support for
+  building myplc itself inside myplc-devel.
+- Move step-specific initialization to appropriate plc.d scripts
+- Fix postgresql startup failure when bootstrapping
+- Allow CA to be configured for each SSL certificate set. Stop doing
+  root CA stuff, this is outside the scope of MyPLC. MyPLC now only
+  generates self-signed certificates, but supports replacement of the
+  self-signed certificates with real certifcates signed by another CA,
+  as long as the CA is specified.
+- Self-sign the MA/SA SSL certificate (and by extension, the MA/SA API
+  certificate).
+- pl_mom: Workarounds for when NM queries time out.
+- plc_api: Honor PLC_MAIL_ENABLED.
+
+* Wed Jul  6 2006 Mark Huang <mlhuang@CS.Princeton.EDU> - 0.4-1, 0.5-1
+- First stable release of MyPLC 0.4 RC1.
+
 * Wed Apr  5 2006 Mark Huang <mlhuang@CS.Princeton.EDU> - 0.2-1
 - Basic functionality complete. Consolidate into a single package
   installed in /plc.
diff --git a/plc_devel_config.xml b/plc_devel_config.xml
new file mode 100644 (file)
index 0000000..e603edd
--- /dev/null
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+Default PLC build environment configuration file
+
+Mark Huang <mlhuang@cs.princeton.edu>
+Copyright (C) 2006 The Trustees of Princeton University
+
+$Id: plc_config.xml,v 1.14 2006/06/23 20:31:09 mlhuang Exp $
+-->
+
+<!DOCTYPE configuration PUBLIC "-//PlanetLab Central//DTD PLC configuration//EN" "plc_config.dtd">
+
+<configuration>
+  <variables>
+    <category id="plc_devel">
+      <name>Build Environment</name>
+      <description>These variables control the behavior of the
+      PlanetLab build environment.</description>
+
+      <variablelist>
+       <variable id="fedora_release" type="string">
+         <name>Fedora Core Release Version</name>
+         <value>4</value>
+         <description>Version number of Fedora Core upon which to
+         base the build environment. Warning: Currently, only Fedora
+         Core 4 is supported.</description>
+       </variable>
+
+       <variable id="fedora_arch" type="string">
+         <name>Fedora Core Base Architecture</name>
+         <value>i386</value>
+         <description>Base architecture of the build
+         environment. Warning: Currently, only i386 is
+         supported.</description>
+       </variable>
+
+       <variable id="fedora_url" type="string">
+         <name>Fedora Core Mirror URL</name>
+         <value>/usr/share/mirrors/fedora</value>
+         <description>Fedora Core mirror from which to install
+         filesystems.</description>
+       </variable>
+
+       <variable id="cvsroot" type="string">
+         <name>CVS Root</name>
+         <value>/cvs</value>
+         <description>CVSROOT to use when checking out code.</description>
+       </variable>
+
+       <variable id="bootstrap" type="boolean">
+         <name>Bootstrap Build</name>
+         <value>false</value>
+         <description>Controls whether MyPLC should be built inside
+         of its own development environment.</description>
+       </variable>
+      </variablelist>
+    </category>
+  </variables>
+
+  <comps>
+    <group>
+      <id>development-libs</id>
+      <name>Development Libraries</name>
+      <default>true</default>
+      <description>The packages in this group are core libraries
+      needed to develop applications.</description>
+      <uservisible>true</uservisible>
+      <packagelist>
+       <!-- This is just a placeholder. The actual group is defined
+            in the Fedora Core 4 comps.xml. -->
+      </packagelist>
+    </group>
+
+    <group>
+      <id>development-tools</id>
+      <name>Development Tools</name>
+      <default>true</default>
+      <description>These tools include core development tools such as
+      automake, gcc, perl, python, and debuggers.</description>
+      <uservisible>true</uservisible>
+      <packagelist>
+       <!-- This is just a placeholder. The actual group is defined
+            in the Fedora Core 4 comps.xml. -->
+      </packagelist>
+    </group>
+
+    <group>
+      <id>legacy-software-development</id>
+      <name>Legacy Software Development</name>
+      <description>These packages provide compatibility support for
+      previous releases.</description>
+      <uservisible>true</uservisible>
+      <packagelist>
+       <!-- This is just a placeholder. The actual group is defined
+            in the Fedora Core 4 comps.xml. -->
+      </packagelist>
+    </group>
+
+    <group>
+      <id>plc-build</id>
+      <name>PlanetLab Build Tools</name>
+      <description>Additional tools required to build PlanetLab
+      software.</description>
+      <packagelist>
+       <!-- kernel-vserver is intended for the vserver-reference, but
+            serves the same useful purpose for MyPLC, namely, to
+            Provide: kernel without actually installing anything. -->
+       <packagereq type="mandatory">kernel-vserver</packagereq>        
+
+       <!-- kernel -->
+       <packagereq type="mandatory">gnupg</packagereq>
+       <packagereq type="mandatory">diffutils</packagereq>
+
+       <!-- util-vserver -->
+       <packagereq type="mandatory">vconfig</packagereq>
+       <packagereq type="mandatory">iptables</packagereq>
+       <packagereq type="mandatory">wget</packagereq>
+       <packagereq type="mandatory">beecrypt-devel</packagereq>
+       <packagereq type="mandatory">tetex-latex</packagereq>
+       <packagereq type="mandatory">gcc-c++</packagereq>
+
+       <!-- ulogd -->
+       <packagereq type="mandatory">libpcap</packagereq>
+
+       <!-- iptables -->
+       <packagereq type="mandatory">linuxdoc-tools</packagereq>
+
+       <!-- vserver-reference -->
+       <packagereq type="mandatory">sudo</packagereq>
+       <packagereq type="mandatory">yum</packagereq>
+       <packagereq type="mandatory">createrepo</packagereq>
+
+       <!-- mysql -->
+       <packagereq type="mandatory">gperf</packagereq>
+       <packagereq type="mandatory">time</packagereq>
+
+       <!-- bootmanager -->
+       <packagereq type="mandatory">sharutils</packagereq>
+
+       <!-- bootcd -->
+       <packagereq type="mandatory">nasm</packagereq>
+       <packagereq type="mandatory">mkisofs</packagereq>
+       <packagereq type="mandatory">dosfstools</packagereq>
+
+       <!-- myplc -->
+       <packagereq type="mandatory">rsync</packagereq>
+      </packagelist>
+    </group>
+
+  </comps>
+
+</configuration>