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)
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
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
33 echo "If specified, the refspec must not be empty"
38 echo "Too many arguments"
44 # Sometimes "make dist" can modify versioned files so we must reset first
47 # Any branch used to create snapshots must already exist
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
)
57 # Configure and dist only if needed
58 if [ ! -e "$SFSNAP_DEST/nagios-plugins-$VS.tar.gz" ]
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