sfsnapshot 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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@shell.sf.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. # Check for *.gz files locally (expect NFS between cf shell server and $CF)
  62. set -x
  63. files=$(ls $IN/*.gz 2>/dev/null)
  64. [[ -z $files ]] && die "No files created"
  65. head_file=$(cd $IN && ls *-trunk-*.gz 2>/dev/null)
  66. ssh -2 $OUT_SERVER "rm -f $OUT/*.gz"
  67. scp -2 $files $OUT_SERVER:$OUT
  68. if [[ -n $head_file ]] ; then
  69. ssh -2 $OUT_SERVER "cd $OUT && ln -s $head_file nagios-plugins-HEAD.tar.gz"
  70. fi
  71. # Create MD5 sum
  72. ssh -2 $OUT_SERVER << EOF
  73. cd $OUT
  74. cat <<-END_README > README
  75. This is the daily SVN snapshot of nagiosplug, consisting of the SVN trunk
  76. and any other branches.
  77. The nagios-plugins-HEAD.tar.gz link will always go to the latest trunk snapshot
  78. (name kept for existing tinderbox scripts to link correctly).
  79. The MD5SUM is:
  80. END_README
  81. md5sum *.gz | tee -a README > MD5SUM
  82. EOF
  83. 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