git-notify: Make the state file group writable
[monitoring-plugins.git] / tools / sfsnapshotgit
blob155259f0d66f0f4f258d641590dd3f6246e44f4b
1 #!/bin/bash
2 # sfsnapshotgit - Snapshot script for Git repository
3 # Original author: Thomas Guyot-Sionnest <tguyot@gmail.com>
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)
10 # Handle command errors (-e) and coder sleep deprivation issues (-u)
11 set -eu
12 trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT
14 # Send all command output to STDERR while allowing us to write to STDOUT
15 # using fd 3
16 exec 3>&1 1>&2
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/snapshot}
25 # If one argument is given, this is the branch to create the snapshot from
26 if [ $# -eq 0 ]
27 then
28 HEAD='master'
29 elif [ $# -eq 1 ]
30 then
31 if [ -z "$1" ]
32 then
33 echo "If specified, the refspec must not be empty"
34 exit
36 HEAD="$1"
37 else
38 echo "Too many arguments"
39 exit
42 # Clean up and pull
43 cd "$SFSNAP_REPO"
44 # Sometimes "make dist" can modify versioned files so we must reset first
45 git reset --hard
46 git clean -qfdx
47 # Any branch used to create snapshots must already exist
48 git checkout "$HEAD"
49 git pull "$SFSNAP_ORIGIN" "$HEAD"
50 # Tags are important for git-describe
51 git fetch --tags "$SFSNAP_ORIGIN"
53 # Write our snapshot version string (similar to NP-VERSION-GEN) to "release"
54 VS=$(git describe --abbrev=4 HEAD)
55 VS=${VS#release-}
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/"
66 # fd 3 goes to STDOUT; print the generated filename
67 echo "nagios-plugins-$VS.tar.gz" 1>&3
69 trap - EXIT