Code

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