typo in BootstrapFS dependency
[build.git] / build.sh
index 6246c98..0eaa02f 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -4,29 +4,30 @@
 # crontabs to build nightly releases (default). Can also be invoked
 # manually to build a tagged release (-r) in the current directory.
 #
-# $Id: build.sh,v 1.11 2004/08/31 14:39:42 mlh-pl_rpm Exp $
+# Mark Huang <mlhuang@cs.princeton.edu>
+# Copyright (C) 2003-2005 The Trustees of Princeton University
 #
+# $Id: build.sh,v 1.43 2007/02/01 16:03:33 mlhuang Exp $
+#
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
 # Set defaults
-CVSROOT=:pserver:anon@build.planet-lab.org:/cvs
-CVS_RSH=ssh
+SVNPATH=https://svn.planet-lab.org/svn
+TAG=trunk
 MODULE=build
-TAG=HEAD
 BASE=$PWD
+PLDISTRO=planetlab
+VSERVER=
 
-# Alpha node repository
-ALPHA_BOOT=build@boot.planet-lab.org
-ALPHA_ROOT=/www/planetlab/install-rpms/archive/planetlab-alpha
-ALPHA_RPMS=/www/planetlab/install-rpms/planetlab-alpha
-
-# Export certain variables
-export CVS_RSH
+# cron does not set USER?
+[ -z "$USER" ] && export USER=$LOGNAME
 
 # Get options
-while getopts "d:r:m:b:x:h" opt ; do
+while getopts "d:r:m:f:b:x:v:h" opt ; do
     case $opt in
        d)
-           CVSROOT=$OPTARG
+           SVNPATH=$OPTARG
            ;;
        r)
            TAG=$OPTARG
@@ -34,27 +35,37 @@ while getopts "d:r:m:b:x:h" opt ; do
        m)
            MAILTO=$OPTARG
            ;;
+       f)
+           PLDISTRO="$OPTARG"
+           ;;
        b)
            BASE=$OPTARG
            ;;
        x)
            BUILDS=$OPTARG
            ;;
+       v)
+           VSERVER=$OPTARG
+           ;;
        h|*)
            echo "usage: `basename $0` [OPTION]..."
-           echo "      -d directory    CVS repository root (default $CVSROOT)"
-           echo "      -r revision     CVS revision to checkout (default $TAG)"
+           echo "      -d directory    SVN repository root (default $SVNPATH)"
+           echo "      -r revision     SVN revision to checkout (default $TAG)"
+           echo "      -v Vserver      Vserver reference to build within (optional)"
            echo "      -m address      Notify recipient of failures (default: none)"
+           echo "      -f distro       Distribution to build (default: $PLDISTRO)"
            echo "      -b base         Run operations in specified base directory (default $BASE)"
            echo "      -x N            Remove all but the last N runs from the base directory (default: none)"
            exit 1
            ;;
     esac
 done
+shift $(($OPTIND - 1))
 
 # Base operations in specified directory
 mkdir -p $BASE
 cd $BASE || exit $?
+BASEDIR=$(pwd)
 
 # Remove old runs
 if [ -n "$BUILDS" ] ; then
@@ -62,7 +73,8 @@ if [ -n "$BUILDS" ] ; then
 fi
 
 # Create a unique build base
-BASE=${TAG/HEAD/`date +%Y.%m.%d`}
+BASE=build_${TAG/trunk/`date +%Y.%m.%d`}
+[ -n "${VSERVER}" ] && BASE=${VSERVER}_${BASE}
 i=
 while ! mkdir ${BASE}${i} 2>/dev/null ; do
     [ -z ${i} ] && BASE=${BASE}.
@@ -75,45 +87,67 @@ done
 BASE=${BASE}${i}
 
 # Redirect output from here
+exec 2>&1
 exec &>${BASE}/log
 
-# XXX Hack to store the pup key as well as the bui key
-eval `ssh-agent`
-for i in `grep -l "BEGIN.*PRIVATE KEY" $HOME/.ssh/*` ; do
-    SSH_ASKPASS=/bin/false ssh-add $i
-done
-
-# Build
-cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
-make -C ${BASE}
-
-if [ $? -ne 0 ] ; then
-    # Notify recipient of failure or just dump to stdout
+failure() {
+    # Notify recipient of failure
     if [ -n "$MAILTO" ] ; then
-       NOTIFY="mail -s 'Failures for ${BASE}' $MAILTO"
-    else
-       NOTIFY=cat
+       tail -c 8k ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
     fi
-    (
-    # Dump log
-    if [ -f ${BASE}/log ] ; then
-       tail -100 ${BASE}/log
-    else
-       echo "Error $?"
+    exit 1
+}
+
+vfailure() {
+    # Notify recipient of failure
+    vnamespace -e $BASE umount ${BASEDIR}/${BASE}/data
+    vserver $BASE stop
+    vserver --silent $BASE delete
+    failure
+    exit 1
+}
+
+trap failure ERR INT
+
+set -x
+
+VCMDPREFIX=
+if [ -n "$VSERVER" ] ; then
+    vserver $BASE build -m clone --rootdir ${BASEDIR} -- --source /vservers/${VSERVER}
+    vserver $BASE start
+    trap vfailure ERR INT
+    if [ -d /data ] ; then
+       vnamespace -e $BASE mount -o ro --bind /data ${BASEDIR}/${BASE}/data
     fi
-    ) | eval $NOTIFY
-elif [ -n "$BUILDS" ] ; then
-    # Remove old nightly runs
-    echo "cd ${ALPHA_ROOT} && ls -t | sed -n ${BUILDS}~1p | xargs rm -rf" | ssh ${ALPHA_BOOT} sh -s
-    # Update alpha node repository
-    for i in RPMS SRPMS ; do
-       ssh ${ALPHA_BOOT} mkdir -p ${ALPHA_ROOT}/${BASE}/${i}
-       find ${BASE}/${i} -type f | xargs -i scp {} ${ALPHA_BOOT}:${ALPHA_ROOT}/${BASE}/${i}
-       ssh ${ALPHA_BOOT} yum-arch ${ALPHA_ROOT}/${BASE}/${i} >/dev/null
-    done
-    # Update symlink
-    ssh ${ALPHA_BOOT} ln -nsf ${ALPHA_ROOT}/${BASE}/RPMS/ ${ALPHA_RPMS}
+
+    # Checkout build directory
+    VSUEXEC="vserver $BASE exec su - build -c"
+
+    $VSUEXEC "svn checkout ${SVNPATH}/${MODULE}/${TAG} ${MODULE}"
+
+    # Build
+    #XXX vserver $BASE suexec build ${MODULE}/make.sh TAG=${TAG} PLDISTRO=${PLDISTRO}
+
+    # Install to boot server
+    # XXX not yet
+
+    trap - ERR INT
+    vnamespace -e $BASE umount ${BASEDIR}/${BASE}/data
+    vserver $BASE stop
+else
+    # Checkout build directory
+    svn checkout ${SVNPATH}/${MODULE}/${TAG} ${BASE}
+
+    # Build myplc-devel-native, install it to ensure we've got the right packages, and let it rip
+    make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} BASE=$BASE BUILDS=$BUILDS MyPLC-devel-native
+    sudo yum -y localinstall RPMS/i386/MyPLC-devel-native-*.*.rpm 
+
+    # Build everything
+    make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} BASE=$BASE BUILDS=$BUILDS
+
+    # Install to boot server
+    # XXX not yet
+    #make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} install BASE=$BASE BUILDS=$BUILDS
 fi
 
-# Kill the current agent
-ssh-agent -k
+exit 0