- add RPMBUILD override variable
[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.10 2004/08/18 16:16:56 mlh-pl_rpm Exp $
8 #
9
10 # Set defaults
11 CVSROOT=bui-pl_rpm@cvs.planet-lab.org:/cvs
12 CVS_RSH=ssh
13 MODULE=rpm
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 &>${BASE}/log
79
80 # XXX Hack to store the pup key as well as the bui key
81 eval `ssh-agent`
82 for i in `grep -l "BEGIN.*PRIVATE KEY" $HOME/.ssh/*` ; do
83     SSH_ASKPASS=/bin/false ssh-add $i
84 done
85
86 # Build
87 cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
88 make -C ${BASE}
89
90 if [ $? -ne 0 ] ; then
91     # Notify recipient of failure or just dump to stdout
92     if [ -n "$MAILTO" ] ; then
93         NOTIFY="mail -s 'Failures for ${BASE}' $MAILTO"
94     else
95         NOTIFY=cat
96     fi
97     (
98     # Dump log
99     if [ -f ${BASE}/log ] ; then
100         tail -100 ${BASE}/log
101     else
102         echo "Error $?"
103     fi
104     ) | eval $NOTIFY
105 elif [ -n "$BUILDS" ] ; then
106     # Remove old nightly runs
107     echo "cd ${ALPHA_ROOT} && ls -t | sed -n ${BUILDS}~1p | xargs rm -rf" | ssh ${ALPHA_BOOT} sh -s
108     # Update alpha node repository
109     for i in RPMS SRPMS ; do
110         ssh ${ALPHA_BOOT} mkdir -p ${ALPHA_ROOT}/${BASE}/${i}
111         find ${BASE}/${i} -type f | xargs -i scp {} ${ALPHA_BOOT}:${ALPHA_ROOT}/${BASE}/${i}
112         ssh ${ALPHA_BOOT} yum-arch ${ALPHA_ROOT}/${BASE}/${i} >/dev/null
113     done
114     # Update symlink
115     ssh ${ALPHA_BOOT} ln -nsf ${ALPHA_ROOT}/${BASE}/RPMS/ ${ALPHA_RPMS}
116 fi
117
118 # Kill the current agent
119 ssh-agent -k