# 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.3 2004/05/26 18:44:50 mlh-pl_rpm Exp $
+# Mark Huang <mlhuang@cs.princeton.edu>
+# Copyright (C) 2003-2005 The Trustees of Princeton University
+#
+# $Id: build.sh,v 1.28 2005/05/04 17:43:14 mlhuang Exp $
#
# Set defaults
-CVSROOT=pup-pl_rpm@cvs.planet-lab.org:/cvs
+CVSROOT=:pserver:anon@cvs.planet-lab.org:/cvs
CVS_RSH=ssh
-MODULE=rpm
+MODULE=build
TAG=HEAD
+BASE=$PWD
+
+# 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:b:x:h" opt ; do
case $opt in
d)
CVSROOT=$OPTARG
r)
TAG=$OPTARG
;;
- *)
- echo "usage: `basename $0` [-d $CVSROOT] [-r $TAG]"
+ m)
+ MAILTO=$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 " -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
+# 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`}
i=
done
BASE=${BASE}${i}
-# Redirect both stdout and stderr to log file
+# Redirect output from here
+exec 2>&1
exec &>${BASE}/log
# Build
cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
make -C ${BASE}
+make -C ${BASE} install BASE=$BASE BUILDS=$BUILDS
+rc=$?
+
+if [ $rc -ne 0 ] ; then
+ # Notify recipient of failure
+ if [ -n "$MAILTO" ] ; then
+ tail -100 ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
+ fi
+ exit $rc
+fi
+
+exit 0