2 # sfsnapshot-upload - Snapshot upload script using sfsnapshotgit
3 # Original author: Thomas Guyot-Sionnest <tguyot@gmail.com>
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)
11 trap 'echo "An error occurred in sfsnapshot-upload 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
=~
/bin
/sfsnapshotgit
22 # Retention time for snapshots (in minutes), 0 for no retention.
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
42 # If we don't keep old snapshots we can clean up all links now
43 if [ $CLEAN_TIME -eq 0 ]
45 find $SFSNAP_DEST -type l
-name '*.gz' -delete
48 for head in $HEADS ; do
49 # This runs the actual snapshot code. It creates new snapshots if needed and always
50 # return the current snapshot file (even if it wasn't modified).
51 file=$
($sfsnapshot $head)
52 # Create main head link
53 ln -sf $file $SFSNAP_DEST/nagios-plugins-
$head.
tar.gz
55 # Keep links by branch name too if we keep old snapshots, so we can keep tracks of them
56 if [ $CLEAN_TIME -gt 0 -a ! -e "$SFSNAP_DEST/nagios-plugins-$head-${file#nagios-plugins-}" ]
58 ln -s $file $SFSNAP_DEST/nagios-plugins-
$head-${file#nagios-plugins-}
61 # Cleanup and re-create backward-compatibility links
62 if [ "$head" == "master" ]
64 for cclean
in $COMPATCLEANUP
66 find $SFSNAP_DEST -type l
-name "nagios-plugins-$cclean.tar.gz" -delete
68 for compat
in $COMPATLINKS
70 ln -sf $file $SFSNAP_DEST/nagios-plugins-
$compat.
tar.gz
77 # Clean up links older than $CLEAN_TIME if needed
78 if [ $CLEAN_TIME -gt 0 ]
80 find .
-type l
-name '*.gz' -mmin +$CLEAN_TIME -delete
83 # Now clean up files that we don't need
84 # 1. loop over actual snapshots
85 for dest
in `find . -type f -name '*.gz' |xargs -n 1 basename`
87 # 2. Loop over the list of linked-to files
88 for current
in `find . -type l -name '*.gz' |xargs -n 1 readlink | sort | uniq`
90 if [ "$current" == "$dest" ]
92 # File is being linked to - don't delete (continue first loop)
96 # No link to this file, we can drop it
101 cat <<-END_README > README
102 This is the latest snapshot of nagiosplug, consisting of the following
106 The nagios-plugins-<head>.tar.gz link will always point to the latest
107 corresponding snapshot (nagios-plugins-<git-describe>.tar.gz).
109 For backward-compatibility, the nagios-plugins-HEAD.tar.gz and
110 nagios-plugins-trunk-<ts> point to their corresponding "master" head.
112 The tarballs will only be updated when a change has been made. The
113 MD5SUM file will be updated each time.
117 md5sum *.gz |
tee -a README
> MD5SUM
120 [ -n "$OUT_SERVER" ] && OUT_SERVER
="$OUT_SERVER:"
121 rsync
-a --exclude=.htaccess
--exclude=HEADER.html
--delete "$SFSNAP_DEST/" "$OUT_SERVER$OUT_PATH"