- remove stupid license notice
[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.28 2005/05/04 17:43:14 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
20 # cron does not set USER?
21 [ -z "$USER" ] && export USER=$LOGNAME
22
23 # Export certain variables
24 export CVS_RSH
25
26 # Get options
27 while getopts "d:r:m:b:x:h" opt ; do
28     case $opt in
29         d)
30             CVSROOT=$OPTARG
31             ;;
32         r)
33             TAG=$OPTARG
34             ;;
35         m)
36             MAILTO=$OPTARG
37             ;;
38         b)
39             BASE=$OPTARG
40             ;;
41         x)
42             BUILDS=$OPTARG
43             ;;
44         h|*)
45             echo "usage: `basename $0` [OPTION]..."
46             echo "      -d directory    CVS repository root (default $CVSROOT)"
47             echo "      -r revision     CVS revision to checkout (default $TAG)"
48             echo "      -m address      Notify recipient of failures (default: none)"
49             echo "      -b base         Run operations in specified base directory (default $BASE)"
50             echo "      -x N            Remove all but the last N runs from the base directory (default: none)"
51             exit 1
52             ;;
53     esac
54 done
55
56 # Base operations in specified directory
57 mkdir -p $BASE
58 cd $BASE || exit $?
59
60 # Remove old runs
61 if [ -n "$BUILDS" ] ; then
62     ls -t | sed -n ${BUILDS}~1p | xargs rm -rf
63 fi
64
65 # Create a unique build base
66 BASE=${TAG/HEAD/`date +%Y.%m.%d`}
67 i=
68 while ! mkdir ${BASE}${i} 2>/dev/null ; do
69     [ -z ${i} ] && BASE=${BASE}.
70     i=$((${i}+1))
71     if [ $i -gt 100 ] ; then
72         echo "$0: Failed to create release directory `pwd`/${BASE}${i}"
73         exit 1
74     fi
75 done
76 BASE=${BASE}${i}
77
78 # Redirect output from here
79 exec 2>&1
80 exec &>${BASE}/log
81
82 # Build
83 cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
84 make -C ${BASE}
85 make -C ${BASE} install BASE=$BASE BUILDS=$BUILDS
86 rc=$?
87
88 if [ $rc -ne 0 ] ; then
89     # Notify recipient of failure
90     if [ -n "$MAILTO" ] ; then
91         tail -100 ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
92     fi
93     exit $rc
94 fi
95
96 exit 0