Code

Add -D_FORTIFY_SOURCE
[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 ...]"
7 # Assumes:
8 #  ssh setup to send to shell.sf.net and $CF without password prompt
9 #  the compile server has all the prerequisites stated at http://nagiosplug.sourceforge.net/developer-guidelines.html
10 # Install in cron with something like:
11 #  47 * * * * $HOME/bin/mail_error -o $HOME/sfsnapshot.out -m tonvoon@users.sf.net sfsnapshot r1_3_0
13 function die { echo $1; exit 1; }
15 # This makes the distribution. Expects $1 as branches/name, otherwise uses trunk
16 function make_dist {
17         if [[ -n $1 ]] ; then
18                 svn_url_suffix=$1
19                 name=${1##*/}
20         else
21                 svn_url_suffix="trunk"
22                 name="trunk"
23         fi
24         v="$name-"
25         
26         # Get compile server to do the work
27         # Variables will be expanded locally before being run on $CF
28         ssh $CF <<EOF
29         set -x
30         PATH=$PATH:/usr/local/bin
31         [[ ! -d $COMPILE_DIR/$name ]] && mkdir -p $COMPILE_DIR/$name
32         cd $COMPILE_DIR/$name
34         # Cannot use cvs export due to conflicts on second run - think this is better for cvs server
35         svn export https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/$svn_url_suffix $PROJECT
37         cd $PROJECT
39         tools/setup
41         ./configure
43         # Make the Nagiosplug dist tarball
44         make dist VERSION=$v$DS RELEASE=snapshot
46         # May fail if file not generated - do not trap
47         mv *.gz $IN
49         rm -rf $COMPILE_DIR
50         # End ssh
51 EOF
52 }
54 # Set working variables
55 PROJECT=nagiosplug
57 # This is local to the compile server for faster compile
58 COMPILE_DIR=/tmp/tonvoon/tmp_snapshot
60 #  Needs to be on NFS so gz file can be read on the compile shell server
61 IN=${HOME}/tmp_snapshot
63 # Where to place the generated files
64 OUT_SERVER="tonvoon@shell.sf.net"
65 OUT="/home/groups/n/na/nagiosplug/htdocs/snapshot"
67 # Make sure prereqs are satisfied on server!
68 CF="localhost"
69 DS=`date -u +%Y%m%d%H%M`
71 # Setup home directory area
72 [[ ! -d $IN ]] && mkdir -p $IN
74 # Make dists for HEAD and any others in command parameters
75 make_dist
76 for i in $* ; do
77         make_dist $i
78 done
80 # Check for *.gz files locally (expect NFS between cf shell server and $CF)
81 set -x
82 files=$(ls $IN/*.gz 2>/dev/null)
83 [[ -z $files ]] && die "No files created"
84 head_file=$(cd $IN && ls *-trunk-*.gz 2>/dev/null)
85 ssh -2 $OUT_SERVER "rm -f $OUT/*.gz"
86 scp -2 $files $OUT_SERVER:$OUT
87 if [[ -n $head_file ]] ; then
88         ssh -2 $OUT_SERVER "cd $OUT && ln -s $head_file nagios-plugins-HEAD.tar.gz"
89 fi
91 # Create MD5 sum
92 ssh -2 $OUT_SERVER << EOF
93 cd $OUT
94 cat <<-END_README > README
95 This is the daily SVN snapshot of nagiosplug, consisting of the SVN trunk
96 and any other branches.
98 The nagios-plugins-HEAD.tar.gz link will always go to the latest trunk snapshot
99 (name kept for existing tinderbox scripts to link correctly).
101 The MD5SUM is:
102 END_README
103 md5sum *.gz | tee -a README > MD5SUM
104 EOF
106 rm -f $files
108 # Work out success or failure
109 expected=$(($# + 1))
110 set -- $files
111 [[ $# -ne $expected ]] && die "Expected $expected, got $#"
112 exit 0