Code

Error code depending on number of files generated
[nagiosplug.git] / tools / sfsnapshot
1 #! /bin/bash
3 # Butchered version of snapshot
4 # Can only run on the shell compile farm server
5 # Will always create a snapshot of HEAD
6 # If want multiple snapshots, just run with "sfsnapshot {branch} [branch2 ...]"
7 # Assumes:
8 #  ssh setup to send to shell.sf.net and $CF without password prompt
9 #  autconf and automake installed on shell cf at v 2.57 & 1.72 and in PATH
11 function die { echo $1; exit 1; }
13 # This makes the distribution. Expects $1 as CVS tag, otherwise uses HEAD
14 function make_dist {
15         if [[ -n $1 ]] ; then
16                 cvs_rel=$1
17                 v="$1-"
18         else
19                 cvs_rel="HEAD"
20                 v=""
21         fi
22         
23         # Get compile server to do the work
24         # Variables will be expanded locally before being run on $CF
25         ssh $CF <<-EOF
26         set -x
27         PATH=$PATH
28         [[ ! -d $IN/$cvs_rel ]] && mkdir -p $IN/$cvs_rel
29         cd $IN/$cvs_rel
30         if [[ -d $PROJECT ]] ; then
31                 cd $PROJECT 
32                 rm configure.in
33                 cvs update -r $cvs_rel
34         else
35                 cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/nagiosplug co -r $cvs_rel nagiosplug
36                 cd $PROJECT
37         fi
39         sed 's/^VER=.*/VER=$v$DS/;s/^REL=.*/REL=snapshot/' configure.in > configure.tmp
40         mv configure.tmp configure.in
41         aclocal -I lib
42         autoheader
43         autoconf
44         automake --add-missing --copy
45         autoreconf
46         ./configure
48         # Make the Nagiosplug dist tarball
49         make dist
51         # End ssh
52         EOF
53 }
55 # Set working variables
56 PROJECT=nagiosplug
57 IN=${HOME}/tmp_snapshot
58 OUT_SERVER="shell.sf.net"
59 OUT="/home/groups/n/na/nagiosplug/htdocs/snapshot"
60 CF="usf-cf-x86-linux-2"
61 DS=`date -u +%Y%m%d%H%M`
63 # Make dists for HEAD and any others in command parameters
64 make_dist
65 for i in $* ; do
66         make_dist $i
67 done
69 # Check for *.gz files locally (expect NFS between cf shell server and $CF)
70 set -x
71 files=$(ls $IN/*/$PROJECT/*.gz 2>/dev/null)
72 [[ -z $files ]] && die "No files created"
73 ssh $OUT_SERVER "rm -f $OUT/*.gz"
74 scp $files $OUT_SERVER:$OUT
76 # Create MD5 sum
77 ssh $OUT_SERVER << EOF
78 cd $OUT
79 md5sum *.gz > MD5SUM
80 EOF
82 rm -f $files
84 # Work out success or failure
85 expected=$(($# + 1))
86 set -- $files
87 [[ $# -ne $expected ]] && die "Expected $expected, got $#"
88 exit 0