sfsnapshot 3.0 KB

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