diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-09-26 18:58:51 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-09-26 19:18:01 (GMT) |
commit | 5b801b81a963d33c1733c524dc8ce11452a5bbbc (patch) | |
tree | 99ae085d7611a00783daf500dbbd77fe061453d3 /tools/sfsnapshotgit | |
parent | 623047109ab5a069cd34cab6b8c4c343fc70b48d (diff) | |
download | monitoring-plugins-5b801b81a963d33c1733c524dc8ce11452a5bbbc.tar.gz |
Enhancements to tools/sfsnapshotgit
Diffstat (limited to 'tools/sfsnapshotgit')
-rwxr-xr-x | tools/sfsnapshotgit | 74 |
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) |
4 | set -eu | 11 | set -eu |
5 | trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT | 12 | trap '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 |
8 | DS=`date -u +%Y%m%d%H%M` | 15 | # using fd 3 |
16 | exec 3>&1 1>&2 | ||
9 | 17 | ||
10 | if [ $# -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: | ||
21 | SFSNAP_REPO=${SFSNAP_REPO-~/staging/nagiosplugins} | ||
22 | SFSNAP_ORIGIN=${SFSNAP_ORIGIN-origin} | ||
23 | SFSNAP_DEST=${SFSNAP_DEST-~/staging} | ||
24 | |||
25 | # If one argument is given, this is the branch to create the snapshot from | ||
26 | if [ $# -eq 0 ] | ||
11 | then | 27 | then |
12 | HEAD='master' | 28 | HEAD='master' |
13 | else | 29 | elif [ $# -eq 1 ] |
14 | HEAD="$1" | ||
15 | fi | ||
16 | |||
17 | if [ -z "$HEAD" ] | ||
18 | then | 30 | then |
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" | ||
37 | else | ||
38 | echo "Too many arguments" | ||
20 | exit | 39 | exit |
21 | fi | 40 | fi |
22 | 41 | ||
23 | # Clean up and pull | 42 | # Clean up and pull |
24 | cd ~/staging/nagiosplugins | 43 | cd "$SFSNAP_REPO" |
44 | # Sometimes "make dist" can modify versioned files so we must reset first | ||
45 | git reset --hard | ||
25 | git clean -qfdx | 46 | git clean -qfdx |
47 | # Any branch used to create snapshots must already exist | ||
26 | git checkout "$HEAD" | 48 | git checkout "$HEAD" |
27 | git pull origin "$HEAD" | 49 | git pull "$SFSNAP_ORIGIN" "$HEAD" |
28 | # Tags are important for git-describe | 50 | # Tags are important for git-describe |
29 | git fetch --tags origin | 51 | git 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" |
32 | VS=$(git describe --abbrev=4 HEAD) | 54 | VS=$(git describe --abbrev=4 HEAD) |
55 | VS=${VS#release-} | ||
56 | |||
57 | # Configure and dist only if needed | ||
58 | if [ ! -e "$SFSNAP_DEST/nagios-plugins-$VS.tar.gz" ] | ||
59 | then | ||
60 | tools/setup | ||
61 | ./configure | ||
62 | make dist VERSION=$VS RELEASE=snapshot | ||
63 | cp nagios-plugins-$VS.tar.gz "$SFSNAP_DEST/" | ||
64 | fi | ||
33 | 65 | ||
34 | # Configure and dist | 66 | # fd 3 goes to STDOUT; print the generated filename |
35 | tools/setup | 67 | echo "nagios-plugins-$VS.tar.gz" 1>&3 |
36 | ./configure | ||
37 | make 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. | ||
48 | mv nagios-plugins-${VS#release-}.tar.gz nagios-plugins-trunk-$DS.tar.gz | ||
49 | cp *.tar.gz /tmp/ | ||
50 | 68 | ||
51 | trap - EXIT | 69 | trap - EXIT |
52 | 70 | ||