util-vserver depends on libnl
[build.git] / build.sh
index 9097e5e..78c6e53 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,28 +1,41 @@
-#!/usr/bin/ssh-agent /bin/bash
+#!/bin/bash
 #
 # PlanetLab release build script. Intended to be used by scripts and
 # 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.7 2004/08/09 15:13:59 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=bui-pl_rpm@cvs.planet-lab.org:/cvs
+if [ -f CVS/Root ] ; then
+    CVSROOT=$(cat CVS/Root)
+    TAG=$(cvs status build.sh | sed -ne 's/[[:space:]]*Sticky Tag:[[:space:]]*\([^[:space:]]*\).*/\1/p')
+    if [ "$TAG" = "(none)" ] ; then
+       TAG=HEAD
+    fi
+else
+    CVSROOT=:pserver:anon@cvs.planet-lab.org:/cvs
+    TAG=HEAD
+fi
 CVS_RSH=ssh
-MODULE=rpm
-TAG=HEAD
+MODULE=build
+BASE=$PWD
+PLDISTRO=planetlab
 
-# 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
+# cron does not set USER?
+[ -z "$USER" ] && export USER=$LOGNAME
 
 # Export certain variables
 export CVS_RSH
 
 # Get options
-while getopts "d:r:" opt ; do
+while getopts "d:r:m:f:b:x:h" opt ; do
     case $opt in
        d)
            CVSROOT=$OPTARG
@@ -30,12 +43,40 @@ while getopts "d:r:" opt ; do
        r)
            TAG=$OPTARG
            ;;
-       *)
-           echo "usage: `basename $0` [-d $CVSROOT] [-r $TAG]"
+       m)
+           MAILTO=$OPTARG
+           ;;
+       f)
+           PLDISTRO="$OPTARG"
+           ;;
+       b)
+           BASE=$OPTARG
+           ;;
+       x)
+           BUILDS=$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 "      -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 $?
+
+# Remove old runs
+if [ -n "$BUILDS" ] ; then
+    ls -t | sed -n ${BUILDS}~1p | xargs rm -rf
+fi
 
 # Create a unique build base
 BASE=${TAG/HEAD/`date +%Y.%m.%d`}
@@ -50,31 +91,29 @@ while ! mkdir ${BASE}${i} 2>/dev/null ; do
 done
 BASE=${BASE}${i}
 
-# XXX Hack to store the pup key as well as the bui key
-for i in `grep -l "BEGIN.*PRIVATE KEY" $HOME/.ssh/*` ; do
-    SSH_ASKPASS=/bin/false ssh-add $i
-done
+# Redirect output from here
+exec 2>&1
+exec &>${BASE}/log
 
-# Build
-(
-cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
-make -C ${BASE}
-) >${BASE}/log 2>&1
-
-if [ $? -ne 0 ] ; then
-    # Dump log
-    if [ -f ${BASE}/log ] ; then
-       tail -100 ${BASE}/log
-    else
-       echo "Error $?"
+failure() {
+    # Notify recipient of failure
+    if [ -n "$MAILTO" ] ; then
+       tail -c 8k ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
     fi
-elif [ "$TAG" = "HEAD" ] ; then
-    # 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}
-fi
+    exit 1
+}
+
+trap failure ERR INT
+
+set -x
+
+# Checkout build directory
+cvs -d ${CVSROOT} checkout -r ${TAG} -d ${BASE} ${MODULE}
+
+# Build
+${BASE}/make.sh TAG=${TAG} PLDISTRO=${PLDISTRO}
+
+# Install to boot server
+make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} install BASE=$BASE BUILDS=$BUILDS
+
+exit 0