sfsnapshot 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 CVS tag, otherwise uses HEAD
  13. function make_dist {
  14. if [[ -n $1 ]] ; then
  15. cvs_rel=$1
  16. v="$1-"
  17. else
  18. cvs_rel="HEAD"
  19. v="HEAD-"
  20. fi
  21. # Get compile server to do the work
  22. # Variables will be expanded locally before being run on $CF
  23. ssh $CF <<EOF
  24. set -x
  25. PATH=$PATH:/usr/local/bin
  26. [[ ! -d $COMPILE_DIR/$cvs_rel ]] && mkdir -p $COMPILE_DIR/$cvs_rel
  27. cd $COMPILE_DIR/$cvs_rel
  28. # Cannot use cvs export due to conflicts on second run - think this is better for cvs server
  29. CVS_RSH=ssh cvs -z3 -d:ext:tonvoon@cvs.sourceforge.net:/cvsroot/nagiosplug co -r $cvs_rel nagiosplug
  30. cd $PROJECT
  31. tools/setup
  32. ./configure
  33. # Make the Nagiosplug dist tarball
  34. make dist VERSION=$v$DS RELEASE=snapshot
  35. # May fail if file not generated - do not trap
  36. mv *.gz $IN
  37. rm -rf $COMPILE_DIR
  38. # End ssh
  39. EOF
  40. }
  41. # Set working variables
  42. PROJECT=nagiosplug
  43. # This is local to the compile server for faster compile
  44. COMPILE_DIR=/tmp/tonvoon/tmp_snapshot
  45. # Needs to be on NFS so gz file can be read on the compile shell server
  46. IN=${HOME}/tmp_snapshot
  47. # Where to place the generated files
  48. OUT_SERVER="shell.sf.net"
  49. OUT="/home/groups/n/na/nagiosplug/htdocs/snapshot"
  50. # Make sure prereqs are satisfied on server!
  51. CF="amd64-linux2"
  52. DS=`date -u +%Y%m%d%H%M`
  53. # Setup home directory area
  54. [[ ! -d $IN ]] && mkdir -p $IN
  55. # Make dists for HEAD and any others in command parameters
  56. make_dist
  57. for i in $* ; do
  58. make_dist $i
  59. done
  60. # Check for *.gz files locally (expect NFS between cf shell server and $CF)
  61. set -x
  62. files=$(ls $IN/*.gz 2>/dev/null)
  63. [[ -z $files ]] && die "No files created"
  64. head_file=$(cd $IN && ls *HEAD*.gz 2>/dev/null)
  65. ssh -2 $OUT_SERVER "rm -f $OUT/*.gz"
  66. scp -2 $files $OUT_SERVER:$OUT
  67. if [[ -n $head_file ]] ; then
  68. ssh -2 $OUT_SERVER "cd $OUT && ln -s $head_file nagios-plugins-HEAD.tar.gz"
  69. fi
  70. # Create MD5 sum
  71. ssh -2 $OUT_SERVER << EOF
  72. cd $OUT
  73. cat <<-END_README > README
  74. This is the daily CVS snapshot of nagiosplug, consisting of the CVS HEAD
  75. and any other branches.
  76. The nagios-plugins-HEAD.tar.gz link will always go to the latest HEAD snapshot.
  77. The MD5SUM is:
  78. END_README
  79. md5sum *.gz | tee -a README > MD5SUM
  80. EOF
  81. rm -f $files
  82. # Work out success or failure
  83. expected=$(($# + 1))
  84. set -- $files
  85. [[ $# -ne $expected ]] && die "Expected $expected, got $#"
  86. exit 0