3 # PlanetLab release build script. Intended to be used by scripts and
4 # crontabs to build nightly releases (default). Can also be invoked
5 # manually to build a tagged release (-r) in the current directory.
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2003-2005 The Trustees of Princeton University
10 # $Id: build.sh,v 1.35 2006/07/06 14:57:50 mlhuang Exp $
14 if [ -f CVS/Root ] ; then
15 CVSROOT=$(cat CVS/Root)
16 TAG=$(cvs status build.sh | sed -ne 's/[[:space:]]*Sticky Tag:[[:space:]]*\([^[:space:]]*\).*/\1/p')
17 if [ "$TAG" = "(none)" ] ; then
21 CVSROOT=:pserver:anon@cvs.planet-lab.org:/cvs
29 # cron does not set USER?
30 [ -z "$USER" ] && export USER=$LOGNAME
32 # Export certain variables
36 while getopts "d:r:m:f:b:x:h" opt ; do
57 echo "usage: `basename $0` [OPTION]..."
58 echo " -d directory CVS repository root (default $CVSROOT)"
59 echo " -r revision CVS revision to checkout (default $TAG)"
60 echo " -m address Notify recipient of failures (default: none)"
61 echo " -f distro Distribution to build (default: $PLDISTRO)"
62 echo " -b base Run operations in specified base directory (default $BASE)"
63 echo " -x N Remove all but the last N runs from the base directory (default: none)"
68 shift $(($OPTIND - 1))
70 # Base operations in specified directory
75 if [ -n "$BUILDS" ] ; then
76 ls -t | sed -n ${BUILDS}~1p | xargs rm -rf
79 # Create a unique build base
80 BASE=${TAG/HEAD/`date +%Y.%m.%d`}
82 while ! mkdir ${BASE}${i} 2>/dev/null ; do
83 [ -z ${i} ] && BASE=${BASE}.
85 if [ $i -gt 100 ] ; then
86 echo "$0: Failed to create release directory `pwd`/${BASE}${i}"
92 # Redirect output from here
97 # Notify recipient of failure
98 if [ -n "$MAILTO" ] ; then
99 tail -c 8k ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
106 # Checkout build directory
107 cvs -d ${CVSROOT} checkout -r ${TAG} -d ${BASE} ${MODULE}
109 # Build development environment first
110 make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} myplc-devel
112 # Build everything else inside the development environment
113 export PLC_ROOT=$BASE/BUILD/myplc-devel-*/myplc/devel/root
114 export PLC_DATA=$BASE/BUILD/myplc-devel-*/myplc/devel/data
117 sudo umount $PLC_ROOT/data/build
118 sudo $BASE/BUILD/myplc-devel-*/myplc/host.init stop
121 trap "cleanup; failure" ERR INT
123 # Start development environment
124 sudo $BASE/BUILD/myplc-devel-*/myplc/host.init start
126 # Cross mount the current build directory to the build user home directory
127 sudo mount -o bind,rw $BASE $PLC_ROOT/data/build
129 # Delete .rpmmacros file so that it gets regenerated with the
130 # appropriate paths relative to the chroot.
134 sudo cp -f /etc/hosts /etc/resolv.conf $PLC_ROOT/etc/
136 # Run the rest of the build
137 sudo chroot $PLC_ROOT su - build -c "make TAG=\"$TAG\" PLDISTRO=\"$PLDISTRO\""
143 # Install to boot server
144 make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} install BASE=$BASE BUILDS=$BUILDS