Code

git-notify: Support SourceForge repositories
[nagiosplug.git] / tools / sfsnapshot
index 47421af4668b30f29df1b1402759a8fbe6e27724..3b71219a765f757b1904ab290953ff9fd1d90183 100755 (executable)
 
 # Butchered version of snapshot
 # Can only run on the shell compile farm server
+# Will always create a snapshot of HEAD
+# If want multiple snapshots, just run with "sfsnapshot [branch ...]"
 # Assumes:
 #  ssh setup to send to shell.sf.net and $CF without password prompt
-#  autconf and automake installed on shell cf at v 2.57 & 1.72 and in PATH
+#  the compile server has all the prerequisites stated at http://nagiosplug.sourceforge.net/developer-guidelines.html
+# Install in cron with something like:
+#  47 * * * * $HOME/bin/mail_error -o $HOME/sfsnapshot.out -m tonvoon@users.sf.net sfsnapshot r1_3_0
 
 function die { echo $1; exit 1; }
 
+# This makes the distribution. Expects $1 as branches/name, otherwise uses trunk
+function make_dist {
+       if [[ -n $1 ]] ; then
+               svn_url_suffix=$1
+               name=${1##*/}
+       else
+               svn_url_suffix="trunk"
+               name="trunk"
+       fi
+       v="$name-"
+       
+       # Get compile server to do the work
+       # Variables will be expanded locally before being run on $CF
+       ssh $CF <<EOF
+       set -x
+       PATH=$PATH:/usr/local/bin
+       [[ ! -d $COMPILE_DIR/$name ]] && mkdir -p $COMPILE_DIR/$name
+       cd $COMPILE_DIR/$name
+
+       # Cannot use cvs export due to conflicts on second run - think this is better for cvs server
+       svn export https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/$svn_url_suffix $PROJECT
+
+       cd $PROJECT
+
+       tools/setup
+
+       ./configure
+
+       # Make the Nagiosplug dist tarball
+       make dist VERSION=$v$DS RELEASE=snapshot
+
+       # May fail if file not generated - do not trap
+       mv *.gz $IN
+
+       rm -rf $COMPILE_DIR
+       # End ssh
+EOF
+}
+
 # Set working variables
 PROJECT=nagiosplug
+
+# This is local to the compile server for faster compile
+COMPILE_DIR=/tmp/tonvoon/tmp_snapshot
+
+#  Needs to be on NFS so gz file can be read on the compile shell server
 IN=${HOME}/tmp_snapshot
-OUT_SERVER="shell.sf.net"
+
+# Where to place the generated files
+OUT_SERVER="tonvoon@web.sourceforge.net"
 OUT="/home/groups/n/na/nagiosplug/htdocs/snapshot"
-CF="usf-cf-x86-linux-2"
+
+# Make sure prereqs are satisfied on server!
+CF="localhost"
 DS=`date -u +%Y%m%d%H%M`
 
-# Get compile server to do the work
-# Variables will be expanded locally before being run on $CF
-ssh $CF <<EOF
-PATH=$PATH
+# Setup home directory area
 [[ ! -d $IN ]] && mkdir -p $IN
-cd ${IN}
-if [[ -d $PROJECT ]] ; then
-       cd $PROJECT 
-       rm -f configure.in
-       cvs update
-else
-       cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/nagiosplug co nagiosplug
-       cd $PROJECT
-fi
 
-sed 's/^VER=.*/VER=${DS}/;s/^REL=.*/REL=snapshot/' configure.in > configure.tmp
-mv configure.tmp configure.in
-aclocal
-autoheader
-autoconf
-automake
-autoreconf
+# Make dists for HEAD and any others in command parameters
+make_dist
+for i in $* ; do
+       make_dist $i
+done
 
-# Make the Nagiosplug dist tarball
-./configure
-make dist
+# Create MD5 sum
+cd $IN
+cat <<-END_README > README
+This is the daily SVN snapshot of nagiosplug, consisting of the SVN trunk
+and any other branches.
+
+The nagios-plugins-HEAD.tar.gz link will always go to the latest trunk snapshot
+(name kept for existing tinderbox scripts to link correctly).
+
+The MD5SUM is:
+END_README
+md5sum *.gz | tee -a README > MD5SUM
 
-# End ssh
-EOF
 
 # Check for *.gz files locally (expect NFS between cf shell server and $CF)
 set -x
-cd $IN/$PROJECT
-ls *.gz > /dev/null 2>&1 || die "No file created"
-ssh $OUT_SERVER "rm -f $OUT/*.gz"
-scp *.gz $OUT_SERVER:$OUT
-rm -f *.gz
+cd $IN
+files=$(ls *.gz 2>/dev/null)
+[[ -z $files ]] && die "No files created"
+head_file=$(cd $IN && ls -rt *-trunk-*.gz | head -1 2>/dev/null)
+cat <<-EOF > /tmp/batchfile.$$
+cd $OUT
+rm *.gz
+put *.gz
+ln $head_file nagios-plugins-HEAD.tar.gz
+put MD5SUM
+put README readme
+EOF
+
+# Do the actual transfer
+# Have to put README down as readme because SF's apache server appears to block README files
+sftp -b /tmp/batchfile.$$ $OUT_SERVER
+
+rm -f $files /tmp/batchfile.$$
 
+# Work out success or failure
+expected=$(($# + 1))
+set -- $files
+[[ $# -ne $expected ]] && die "Expected $expected, got $#"
+exit 0