summaryrefslogtreecommitdiffstats
path: root/tools/sfsnapshotgit
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-09-26 18:58:51 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-09-26 19:18:01 (GMT)
commit5b801b81a963d33c1733c524dc8ce11452a5bbbc (patch)
tree99ae085d7611a00783daf500dbbd77fe061453d3 /tools/sfsnapshotgit
parent623047109ab5a069cd34cab6b8c4c343fc70b48d (diff)
downloadmonitoring-plugins-5b801b81a963d33c1733c524dc8ce11452a5bbbc.tar.gz
Enhancements to tools/sfsnapshotgit
Diffstat (limited to 'tools/sfsnapshotgit')
-rwxr-xr-xtools/sfsnapshotgit74
1 files changed, 46 insertions, 28 deletions
diff --git a/tools/sfsnapshotgit b/tools/sfsnapshotgit
index df0dc35..11bf3b9 100755
--- a/tools/sfsnapshotgit
+++ b/tools/sfsnapshotgit
@@ -1,52 +1,70 @@
1#!/bin/bash 1#!/bin/bash
2# sfsnapshotgit - Snapshot script for Git repository
3# Original author: Thomas Gguyot-Sionnest <tguyot@unix.net>
4#
5# Given an optional branch name (master by default), this script creates
6# a snapshot from the tip of the branch and move it to ~/staging/.
7# The repository, origin and destination directory can be overridden
8# with environment variable (see below)
2 9
3# Handle command errors (-e) and coder sleep deprivation issues (-u) 10# Handle command errors (-e) and coder sleep deprivation issues (-u)
4set -eu 11set -eu
5trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT 12trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT
6 13
7# Timestamp 14# Send all command output to STDERR while allowing us to write to STDOUT
8DS=`date -u +%Y%m%d%H%M` 15# using fd 3
16exec 3>&1 1>&2
9 17
10if [ $# -ne 1 ] 18# Git repository, origin and destination directory can be overridden by
19# setting SFSNAP_REPO, SFSNAP_ORIGIN and SFSNAP_DEST respectively from the
20# caller The defaults are:
21SFSNAP_REPO=${SFSNAP_REPO-~/staging/nagiosplugins}
22SFSNAP_ORIGIN=${SFSNAP_ORIGIN-origin}
23SFSNAP_DEST=${SFSNAP_DEST-~/staging}
24
25# If one argument is given, this is the branch to create the snapshot from
26if [ $# -eq 0 ]
11then 27then
12 HEAD='master' 28 HEAD='master'
13else 29elif [ $# -eq 1 ]
14 HEAD="$1"
15fi
16
17if [ -z "$HEAD" ]
18then 30then
19 echo "If specified, the refspec must not be empty" 31 if [ -z "$1" ]
32 then
33 echo "If specified, the refspec must not be empty"
34 exit
35 fi
36 HEAD="$1"
37else
38 echo "Too many arguments"
20 exit 39 exit
21fi 40fi
22 41
23# Clean up and pull 42# Clean up and pull
24cd ~/staging/nagiosplugins 43cd "$SFSNAP_REPO"
44# Sometimes "make dist" can modify versioned files so we must reset first
45git reset --hard
25git clean -qfdx 46git clean -qfdx
47# Any branch used to create snapshots must already exist
26git checkout "$HEAD" 48git checkout "$HEAD"
27git pull origin "$HEAD" 49git pull "$SFSNAP_ORIGIN" "$HEAD"
28# Tags are important for git-describe 50# Tags are important for git-describe
29git fetch --tags origin 51git fetch --tags "$SFSNAP_ORIGIN"
30 52
31# Write our snapshot version string (similar to NP-VERSION-GEN) to "release" 53# Write our snapshot version string (similar to NP-VERSION-GEN) to "release"
32VS=$(git describe --abbrev=4 HEAD) 54VS=$(git describe --abbrev=4 HEAD)
55VS=${VS#release-}
56
57# Configure and dist only if needed
58if [ ! -e "$SFSNAP_DEST/nagios-plugins-$VS.tar.gz" ]
59then
60 tools/setup
61 ./configure
62 make dist VERSION=$VS RELEASE=snapshot
63 cp nagios-plugins-$VS.tar.gz "$SFSNAP_DEST/"
64fi
33 65
34# Configure and dist 66# fd 3 goes to STDOUT; print the generated filename
35tools/setup 67echo "nagios-plugins-$VS.tar.gz" 1>&3
36./configure
37make dist VERSION=${VS#release-} RELEASE=snapshot
38
39# The rest is probably going to change... The mv below is for backwards
40# compatibility, however I'd recommend:
41# ln -s nagios-plugins-${VS#release-}.tar.gz nagios-plugins-$HEAD.tar.gz
42# ln -s nagios-plugins-${VS#release-}.tar.gz nagios-plugins-trunk-$DS.tar.gz
43# ln -s nagios-plugins-master.tar.gz nagios-plugins-HEAD.tar.gz
44# NB: the 3rd one would be permannent, no need to do it each time
45# Additionally, we could check whenever we need to re-generate a snapshot.
46# This way we could make snapshots much more often as only symlink changes
47# would have to be uploaded.
48mv nagios-plugins-${VS#release-}.tar.gz nagios-plugins-trunk-$DS.tar.gz
49cp *.tar.gz /tmp/
50 68
51trap - EXIT 69trap - EXIT
52 70