sfsnapshot-upload 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # sfsnapshot-upload - Snapshot upload script using sfsnapshotgit
  3. # Original author: Thomas Guyot-Sionnest <tguyot@gmail.com>
  4. #
  5. # This script uses sfsnapshotgit to update the snapshot is needed and upload
  6. # it to SourceForge. The branches to create snapshot from can be given as an
  7. # argument, otherwise the default is master.
  8. # Handle command errors (-e) and coder sleep deprivation issues (-u)
  9. set -eu
  10. trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT
  11. # This can be used to override the default in sfsnapshotgit:
  12. export SFSNAP_REPO=~/staging/nagiosplugins
  13. export SFSNAP_ORIGIN=origin
  14. export SFSNAP_DEST=~/staging/snapshot
  15. ## Some stuff that shouldn't change often...
  16. # The file we'll use to create the snapshot
  17. sfsnapshot=~/sfsnapshotgit
  18. # Retention time for snapshots (in minutes)
  19. CLEAN_TIME=1440
  20. # Where to place the generated files
  21. OUT_SERVER="tonvoon@frs.sourceforge.net"
  22. OUT_PATH="/home/groups/n/na/nagiosplug/htdocs/snapshot"
  23. # Links to always point to the master branch for backwards-compatibility
  24. COMPATLINKS="HEAD trunk-`date -u +%Y%m%d%H%M`"
  25. # And compatibility links to always delete except the last one
  26. COMPATCLEANUP="trunk-*"
  27. # If one or more argument is given, this is the branches to create the snapshots from
  28. if [ $# -eq 0 ]
  29. then
  30. HEADS='master'
  31. else
  32. HEADS=$@
  33. fi
  34. for head in $HEADS ; do
  35. file=$($sfsnapshot $head)
  36. ln -sf $file $SFSNAP_DEST/nagios-plugins-$head.tar.gz
  37. # Keep links by branch name too
  38. [ -f "$SFSNAP_DEST/nagios-plugins-$head-${file#nagios-plugins-}" ] || ln -s $file $SFSNAP_DEST/nagios-plugins-$head-${file#nagios-plugins-}
  39. if [ "$head" == "master" ]
  40. then
  41. for cclean in $COMPATCLEANUP
  42. do
  43. find . -type l -name "nagios-plugins-$cclean.tar.gz" -delete
  44. done
  45. for compat in $COMPATLINKS
  46. do
  47. ln -sf $file $SFSNAP_DEST/nagios-plugins-$compat.tar.gz
  48. done
  49. fi
  50. done
  51. # Cleanup old snapshots and links...
  52. cd $SFSNAP_DEST
  53. # Clean up links older than $CLEAN_TIME
  54. find . -type l -name '*.gz' -mmin +$CLEAN_TIME -delete
  55. # Then clean up files that we don't need
  56. for dest in `find . -type f -name '*.gz' |xargs -n 1 basename`
  57. do
  58. # Loop over the list of linked-to files
  59. for current in `find . -type l -name '*.gz' |xargs -n 1 readlink | uniq`
  60. do
  61. if [ "$current" == "$dest" ]
  62. then
  63. continue 2
  64. fi
  65. done
  66. rm -f $dest
  67. done
  68. # Create MD5 sum
  69. cat <<-END_README > README
  70. This is the latest snapshot of nagiosplug, consisting of the following
  71. head(s):
  72. $HEADS
  73. The nagios-plugins-<head>.tar.gz link will always point to the latest
  74. corresponding snapshot (nagios-plugins-<git-describe>.tar.gz).
  75. For backward-compatibility, the nagios-plugins-HEAD.tar.gz and
  76. nagios-plugins-trunk-<ts> point to their corresponding "master" head.
  77. The MD5SUM are:
  78. END_README
  79. md5sum *.gz | tee -a README > MD5SUM
  80. # Sync the files
  81. [ -n "$OUT_SERVER" ] && OUT_SERVER="$OUT_SERVER:"
  82. rsync -a --exclude=.htaccess --exclude=HEADER.html --delete "$SFSNAP_DEST/" "$OUT_SERVER$OUT_PATH"
  83. trap - EXIT