same with bootmanager
[build.git] / build.sh
index 90f6885..78c6e53 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -4,26 +4,38 @@
 # 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.12 2004/09/22 15:21:18 mlhuang 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
+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=build
-TAG=HEAD
 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:m:b:x:h" opt ; do
+while getopts "d:r:m:f:b:x:h" opt ; do
     case $opt in
        d)
            CVSROOT=$OPTARG
@@ -34,6 +46,9 @@ while getopts "d:r:m:b:x:h" opt ; do
        m)
            MAILTO=$OPTARG
            ;;
+       f)
+           PLDISTRO="$OPTARG"
+           ;;
        b)
            BASE=$OPTARG
            ;;
@@ -45,12 +60,14 @@ while getopts "d:r:m:b:x:h" opt ; do
            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
@@ -78,43 +95,25 @@ BASE=${BASE}${i}
 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
+failure() {
+    # Notify recipient of failure
+    if [ -n "$MAILTO" ] ; then
+       tail -c 8k ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
+    fi
+    exit 1
+}
+
+trap failure ERR INT
+
+set -x
+
+# Checkout build directory
+cvs -d ${CVSROOT} checkout -r ${TAG} -d ${BASE} ${MODULE}
 
 # Build
-cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
-make -C ${BASE}
+${BASE}/make.sh TAG=${TAG} PLDISTRO=${PLDISTRO}
 
-if [ $? -ne 0 ] ; then
-    # Notify recipient of failure or just dump to stdout
-    if [ -n "$MAILTO" ] ; then
-       NOTIFY="mail -s 'Failures for ${BASE}' $MAILTO"
-    else
-       NOTIFY=cat
-    fi
-    (
-    # Dump log
-    if [ -f ${BASE}/log ] ; then
-       tail -100 ${BASE}/log
-    else
-       echo "Error $?"
-    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}
-fi
+# Install to boot server
+make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} install BASE=$BASE BUILDS=$BUILDS
 
-# Kill the current agent
-ssh-agent -k
+exit 0