same with bootmanager
[build.git] / build.sh
index 4aca255..78c6e53 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -4,21 +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.20 2004/12/01 03:23:48 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
+
+# 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
@@ -29,6 +46,9 @@ while getopts "d:r:m:b:x:h" opt ; do
        m)
            MAILTO=$OPTARG
            ;;
+       f)
+           PLDISTRO="$OPTARG"
+           ;;
        b)
            BASE=$OPTARG
            ;;
@@ -40,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
@@ -73,54 +95,25 @@ BASE=${BASE}${i}
 exec 2>&1
 exec &>${BASE}/log
 
-# Build
-cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
-make -C ${BASE}
-rc=$?
-
-if [ $rc -ne 0 ] ; then
+failure() {
     # Notify recipient of failure
     if [ -n "$MAILTO" ] ; then
-       tail -100 ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
+       tail -c 8k ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
     fi
-    exit $rc
-fi
+    exit 1
+}
+
+trap failure ERR INT
 
-# XXX For debugging
 set -x
 
-# XXX Should check out a tagged version of yumgroups.xml
-cvs -d ${CVSROOT} checkout -p alpina/groups/v3_yumgroups.xml > ${BASE}/RPMS/yumgroups.xml
-
-# Create package manifest
-URLBASE=$(cd ${BASE} && pwd -P)
-URLBASE="http://build.planet-lab.org/${URLBASE##$HOME/}/SRPMS"
-${BASE}/packages.sh -b ${URLBASE} ${BASE}/SRPMS > ${BASE}/SRPMS/packages.xml
-
-# Upload packages to boot server
-SERVER=build@boot.planet-lab.org
-ARCHIVE=/www/planetlab/install-rpms/archive
-# Put nightly alpha builds in a subdirectory
-if [ "$TAG" = "HEAD" ] ; then
-    ARCHIVE=$ARCHIVE/planetlab-alpha
-    REPOS=/www/planetlab/install-rpms/planetlab-alpha
-fi
+# Checkout build directory
+cvs -d ${CVSROOT} checkout -r ${TAG} -d ${BASE} ${MODULE}
 
-# Remove old runs
-if [ -n "$BUILDS" ] ; then
-    echo "cd $ARCHIVE && ls -t | sed -n ${BUILDS}~1p | xargs rm -rf" | ssh $SERVER /bin/bash -s
-fi
-
-# Populate repository
-for RPMS in RPMS SRPMS ; do
-    ssh $SERVER mkdir -p $ARCHIVE/$BASE/$RPMS/
-    find $BASE/$RPMS/ -type f | xargs -i scp {} $SERVER:$ARCHIVE/$BASE/$RPMS/
-    ssh $SERVER yum-arch $ARCHIVE/$BASE/$RPMS/ >/dev/null
-done
+# Build
+${BASE}/make.sh TAG=${TAG} PLDISTRO=${PLDISTRO}
 
-# Update nightly alpha symlink
-if [ "$TAG" = "HEAD" ] ; then
-    ssh $SERVER ln -nsf $ARCHIVE/$BASE/RPMS/ $REPOS
-fi
+# Install to boot server
+make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} install BASE=$BASE BUILDS=$BUILDS
 
 exit 0