- fix how URL base is calculated
[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 # $Id: build.sh,v 1.18 2004/10/30 16:01:03 mlhuang Exp $
8 #
9
10 # Set defaults
11 CVSROOT=:pserver:anon@build.planet-lab.org:/cvs
12 CVS_RSH=ssh
13 MODULE=build
14 TAG=HEAD
15 BASE=$PWD
16
17 # Alpha node repository
18 ALPHA_BOOT=build@boot.planet-lab.org
19 ALPHA_ROOT=/www/planetlab/install-rpms/archive/planetlab-alpha
20 ALPHA_RPMS=/www/planetlab/install-rpms/planetlab-alpha
21
22 # Export certain variables
23 export CVS_RSH
24
25 # Get options
26 while getopts "d:r:m:b:x:h" opt ; do
27     case $opt in
28         d)
29             CVSROOT=$OPTARG
30             ;;
31         r)
32             TAG=$OPTARG
33             ;;
34         m)
35             MAILTO=$OPTARG
36             ;;
37         b)
38             BASE=$OPTARG
39             ;;
40         x)
41             BUILDS=$OPTARG
42             ;;
43         h|*)
44             echo "usage: `basename $0` [OPTION]..."
45             echo "      -d directory    CVS repository root (default $CVSROOT)"
46             echo "      -r revision     CVS revision to checkout (default $TAG)"
47             echo "      -m address      Notify recipient of failures (default: none)"
48             echo "      -b base         Run operations in specified base directory (default $BASE)"
49             echo "      -x N            Remove all but the last N runs from the base directory (default: none)"
50             exit 1
51             ;;
52     esac
53 done
54
55 # Base operations in specified directory
56 mkdir -p $BASE
57 cd $BASE || exit $?
58
59 # Remove old runs
60 if [ -n "$BUILDS" ] ; then
61     ls -t | sed -n ${BUILDS}~1p | xargs rm -rf
62 fi
63
64 # Create a unique build base
65 BASE=${TAG/HEAD/`date +%Y.%m.%d`}
66 i=
67 while ! mkdir ${BASE}${i} 2>/dev/null ; do
68     [ -z ${i} ] && BASE=${BASE}.
69     i=$((${i}+1))
70     if [ $i -gt 100 ] ; then
71         echo "$0: Failed to create release directory `pwd`/${BASE}${i}"
72         exit 1
73     fi
74 done
75 BASE=${BASE}${i}
76
77 # Redirect output from here
78 exec 2>&1
79 exec &>${BASE}/log
80
81 # Build
82 cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
83 make -C ${BASE}
84 rc=$?
85
86 if [ $rc -ne 0 ] ; then
87     # Notify recipient of failure
88     if [ -n "$MAILTO" ] ; then
89         tail -100 ${BASE}/log | mail -s "Failures for ${BASE}" $MAILTO
90     fi
91     exit $rc
92 fi
93
94 # Create package manifest
95 URLBASE=$(cd ${BASE} && pwd -P)
96 URLBASE="http://build.planet-lab.org/${URLBASE##$HOME/}/SRPMS"
97 ${BASE}/packages.sh -b ${URLBASE} ${BASE}/SRPMS > ${BASE}/SRPMS/packages.xml
98
99 # Usually only the nightly build specifies -x
100 if [ -n "$BUILDS" ] ; then
101     # Remove old nightly runs
102     echo "cd ${ALPHA_ROOT} && ls -t | sed -n ${BUILDS}~1p | xargs rm -rf" | ssh ${ALPHA_BOOT} /bin/bash -s
103     # Update alpha node repository
104     for i in RPMS SRPMS ; do
105         ssh ${ALPHA_BOOT} mkdir -p ${ALPHA_ROOT}/${BASE}/${i}
106         find ${BASE}/${i} -type f | xargs -i scp {} ${ALPHA_BOOT}:${ALPHA_ROOT}/${BASE}/${i}
107         ssh ${ALPHA_BOOT} yum-arch ${ALPHA_ROOT}/${BASE}/${i} >/dev/null
108     done
109     # Update symlink
110     ssh ${ALPHA_BOOT} ln -nsf ${ALPHA_ROOT}/${BASE}/RPMS/ ${ALPHA_RPMS}
111 fi
112
113 exit 0