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.41 2007/01/22 04:19:06 mlhuang Exp $
13 PATH=/sbin:/bin:/usr/sbin:/usr/bin
16 if [ -f CVS/Root ] ; then
17 CVSROOT=$(cat CVS/Root)
18 TAG=$(cvs status build.sh | sed -ne 's/[[:space:]]*Sticky Tag:[[:space:]]*\([^[:space:]]*\).*/\1/p')
19 if [ "$TAG" = "(none)" ] ; then
23 CVSROOT=:pserver:anon@cvs.planet-lab.org:/cvs
31 # cron does not set USER?
32 [ -z "$USER" ] && export USER=$LOGNAME
34 # Export certain variables
38 while getopts "d:r:m:f:b:x:h" opt ; do
59 echo "usage: `basename $0` [OPTION]..."
60 echo " -d directory CVS repository root (default $CVSROOT)"
61 echo " -r revision CVS revision to checkout (default $TAG)"
62 echo " -m address Notify recipient of failures (default: none)"
63 echo " -f distro Distribution to build (default: $PLDISTRO)"
64 echo " -b base Run operations in specified base directory (default $BASE)"
65 echo " -x N Remove all but the last N runs from the base directory (default: none)"
70 shift $(($OPTIND - 1))
72 # Base operations in specified directory
77 if [ -n "$BUILDS" ] ; then
78 ls -t | sed -n ${BUILDS}~1p | xargs rm -rf
81 # Create a unique build base
82 BASE=${TAG/HEAD/`date +%Y.%m.%d`}
84 while ! mkdir ${BASE}${i} 2>/dev/null ; do
85 [ -z ${i} ] && BASE=${BASE}.
87 if [ $i -gt 100 ] ; then
88 echo "$0: Failed to create release directory `pwd`/${BASE}${i}"
94 # Redirect output from here
99 # Notify recipient of failure
100 if [ -n "$MAILTO" ] ; then
101 tail -c 8k ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
110 # Checkout build directory
111 cvs -d ${CVSROOT} checkout -r ${TAG} -d ${BASE} ${MODULE}
113 # Build development environment first
114 make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} myplc-devel
116 # Build everything else inside the development environment
117 export PLC_ROOT=$(echo $BASE/BUILD/myplc-devel-*/myplc/devel/root)
118 export PLC_DATA=$(echo $BASE/BUILD/myplc-devel-*/myplc/devel/data)
121 sudo umount $PLC_ROOT/data/fedora
122 sudo umount $PLC_ROOT/data/build
123 sudo $BASE/BUILD/myplc-devel-*/myplc/host.init stop
126 trap "cleanup; failure" ERR INT
128 # Start development environment
129 sudo $BASE/BUILD/myplc-devel-*/myplc/host.init start
131 # Cross mount the current build directory to the build user home directory
132 sudo mount -o bind,rw $BASE $PLC_ROOT/data/build
134 # Also cross mount /data/fedora if it exists
135 if [ -d /data/fedora ] ; then
136 sudo mkdir -p $PLC_ROOT/data/fedora
137 sudo mount -o bind,ro /data/fedora $PLC_ROOT/data/fedora
140 # Delete .rpmmacros and parseSpec files so that they get regenerated
141 # appropriately in the development environment.
142 rm -f $BASE/.rpmmacros $BASE/parseSpec
145 sudo cp -f /etc/hosts /etc/resolv.conf $PLC_ROOT/etc/
147 # Run the rest of the build
148 sudo chroot $PLC_ROOT su - build -c "make TAG=\"$TAG\" PLDISTRO=\"$PLDISTRO\""
154 # Install to boot server
155 make TAG=${TAG} PLDISTRO=${PLDISTRO} -C ${BASE} install BASE=$BASE BUILDS=$BUILDS