diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-10-25 10:33:10 -0400 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-10-29 14:17:30 -0400 |
commit | 61e77e54d71579d3717963ae6286922aed9d12d9 (patch) | |
tree | 274f6edd608dd08238dbb51c5e352b36b4f36f64 /tools/sfsnapshot-upload | |
parent | e2ba9ba91fbfcad53892c7ecfb1842dd9e62962a (diff) | |
download | monitoring-plugins-61e77e54d71579d3717963ae6286922aed9d12d9.tar.gz |
Add snapshots upload scripts
Diffstat (limited to 'tools/sfsnapshot-upload')
-rwxr-xr-x | tools/sfsnapshot-upload | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tools/sfsnapshot-upload b/tools/sfsnapshot-upload new file mode 100755 index 00000000..1507cffc --- /dev/null +++ b/tools/sfsnapshot-upload | |||
@@ -0,0 +1,100 @@ | |||
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 | |||
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 | ||
12 | |||
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 | ||
17 | |||
18 | ## Some stuff that shouldn't change often... | ||
19 | # The file we'll use to create the snapshot | ||
20 | sfsnapshot=~/sfsnapshotgit | ||
21 | |||
22 | # Retention time for snapshots (in minutes) | ||
23 | CLEAN_TIME=1440 | ||
24 | |||
25 | # Where to place the generated files | ||
26 | OUT_SERVER="tonvoon@frs.sourceforge.net" | ||
27 | OUT_PATH="/home/groups/n/na/nagiosplug/htdocs/snapshot" | ||
28 | |||
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-*" | ||
33 | |||
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 | ||
41 | |||
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 | ||
59 | |||
60 | # Cleanup old snapshots and links... | ||
61 | cd $SFSNAP_DEST | ||
62 | |||
63 | # Clean up links older than $CLEAN_TIME | ||
64 | find . -type l -name '*.gz' -mmin +$CLEAN_TIME -delete | ||
65 | |||
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 | ||
79 | |||
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 | ||
85 | |||
86 | The nagios-plugins-<head>.tar.gz link will always point to the latest | ||
87 | corresponding snapshot (nagios-plugins-<git-describe>.tar.gz). | ||
88 | |||
89 | For backward-compatibility, the nagios-plugins-HEAD.tar.gz and | ||
90 | nagios-plugins-trunk-<ts> point to their corresponding "master" head. | ||
91 | |||
92 | The MD5SUM are: | ||
93 | END_README | ||
94 | md5sum *.gz | tee -a README > MD5SUM | ||
95 | |||
96 | # Sync the files | ||
97 | rsync -a --exclude=.htaccess --exclude=HEADER.html --delete "$SFSNAP_DEST/" "$OUT_SERVER:$OUT_PATH" | ||
98 | |||
99 | trap - EXIT | ||
100 | |||