- sidewinder no longer a part of this release
[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
16 # Alpha node repository
17 ALPHA_BOOT=build@boot.planet-lab.org
18 ALPHA_ROOT=/www/planetlab/install-rpms/archive/planetlab-alpha
19 ALPHA_RPMS=/www/planetlab/install-rpms/planetlab-alpha
20
21 # Export certain variables
22 export CVS_RSH
23
24 # Get options
25 while getopts "d:r:" opt ; do
26     case $opt in
27         d)
28             CVSROOT=$OPTARG
29             ;;
30         r)
31             TAG=$OPTARG
32             ;;
33         *)
34             echo "usage: `basename $0` [-d $CVSROOT] [-r $TAG]"
35             exit 1
36             ;;
37     esac
38 done
39
40 # Create a unique build base
41 BASE=${TAG/HEAD/`date +%Y.%m.%d`}
42 i=
43 while ! mkdir ${BASE}${i} 2>/dev/null ; do
44     [ -z ${i} ] && BASE=${BASE}.
45     i=$((${i}+1))
46     if [ $i -gt 100 ] ; then
47         echo "$0: Failed to create release directory `pwd`/${BASE}${i}"
48         exit 1
49     fi
50 done
51 BASE=${BASE}${i}
52
53 # Build
54 (
55 # XXX Hack to store the pup key as well as the bui key
56 eval `ssh-agent`
57 for i in `grep -l "BEGIN.*PRIVATE KEY" $HOME/.ssh/*` ; do
58     SSH_ASKPASS=/bin/false ssh-add $i
59 done
60
61 cvs -d ${CVSROOT} export -r ${TAG} -d ${BASE} ${MODULE}
62 make -C ${BASE}
63 ) >${BASE}/log 2>&1
64
65 if [ $? -ne 0 ] ; then
66     # Dump log
67     if [ -f ${BASE}/log ] ; then
68         tail -100 ${BASE}/log
69     else
70         echo "Error $?"
71     fi
72 elif [ "$TAG" = "HEAD" ] ; then
73     # Update alpha node repository
74     for i in RPMS SRPMS ; do
75         ssh ${ALPHA_BOOT} mkdir -p ${ALPHA_ROOT}/${BASE}/${i}
76         find ${BASE}/${i} -type f | xargs -i scp {} ${ALPHA_BOOT}:${ALPHA_ROOT}/${BASE}/${i}
77         ssh ${ALPHA_BOOT} yum-arch ${ALPHA_ROOT}/${BASE}/${i} >/dev/null
78     done
79     # Update symlink
80     ssh ${ALPHA_BOOT} ln -nsf ${ALPHA_ROOT}/${BASE}/RPMS/ ${ALPHA_RPMS}
81 fi
82
83 # Kill the current agent
84 ssh-agent -k