- add twiki to internal build
[build.git] / build.sh
1 #!/bin/bash
2 #
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.
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2003-2005 The Trustees of Princeton University
9 #
10 # $Id: build.sh,v 1.30 2005/05/04 20:34:59 mlhuang Exp $
11 #
12
13 # Set defaults
14 CVSROOT=:pserver:anon@cvs.planet-lab.org:/cvs
15 CVS_RSH=ssh
16 MODULE=build
17 TAG=HEAD
18 BASE=$PWD
19 MAKEFILE=Makefile
20
21 # cron does not set USER?
22 [ -z "$USER" ] && export USER=$LOGNAME
23
24 # Export certain variables
25 export CVS_RSH
26
27 # Get options
28 while getopts "d:r:m:f:b:x:h" opt ; do
29     case $opt in
30         d)
31             CVSROOT=$OPTARG
32             ;;
33         r)
34             TAG=$OPTARG
35             ;;
36         m)
37             MAILTO=$OPTARG
38             ;;
39         f)
40             MAKEFILE=$OPTARG
41             ;;
42         b)
43             BASE=$OPTARG
44             ;;
45         x)
46             BUILDS=$OPTARG
47             ;;
48         h|*)
49             echo "usage: `basename $0` [OPTION]..."
50             echo "      -d directory    CVS repository root (default $CVSROOT)"
51             echo "      -r revision     CVS revision to checkout (default $TAG)"
52             echo "      -m address      Notify recipient of failures (default: none)"
53             echo "      -b base         Run operations in specified base directory (default $BASE)"
54             echo "      -x N            Remove all but the last N runs from the base directory (default: none)"
55             exit 1
56             ;;
57     esac
58 done
59 shift $(($OPTIND - 1))
60
61 # Base operations in specified directory
62 mkdir -p $BASE
63 cd $BASE || exit $?
64
65 # Remove old runs
66 if [ -n "$BUILDS" ] ; then
67     ls -t | sed -n ${BUILDS}~1p | xargs rm -rf
68 fi
69
70 # Create a unique build base
71 BASE=${TAG/HEAD/`date +%Y.%m.%d`}
72 i=
73 while ! mkdir ${BASE}${i} 2>/dev/null ; do
74     [ -z ${i} ] && BASE=${BASE}.
75     i=$((${i}+1))
76     if [ $i -gt 100 ] ; then
77         echo "$0: Failed to create release directory `pwd`/${BASE}${i}"
78         exit 1
79     fi
80 done
81 BASE=${BASE}${i}
82
83 # Redirect output from here
84 exec 2>&1
85 exec &>${BASE}/log
86
87 # Build
88 cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
89 make -f ${MAKEFILE} -C ${BASE} && \
90 make -f ${MAKEFILE} -C ${BASE} install BASE=$BASE BUILDS=$BUILDS
91 rc=$?
92
93 if [ $rc -ne 0 ] ; then
94     # Notify recipient of failure
95     if [ -n "$MAILTO" ] ; then
96         tail -100 ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
97     fi
98     exit $rc
99 fi
100
101 exit 0