diff options
Diffstat (limited to 'bin/build-snapshot')
-rwxr-xr-x | bin/build-snapshot | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/bin/build-snapshot b/bin/build-snapshot new file mode 100755 index 0000000..18777a5 --- /dev/null +++ b/bin/build-snapshot | |||
@@ -0,0 +1,83 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # Copyright (c) 2013 Nagios Plugins Development Team | ||
4 | # | ||
5 | # Originally written by Holger Weiss <holger@zedat.fu-berlin.de>. | ||
6 | # | ||
7 | # This file is free software; the Nagios Plugins Development Team gives | ||
8 | # unlimited permission to copy and/or distribute it, with or without | ||
9 | # modifications, as long as this notice is preserved. | ||
10 | # | ||
11 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
12 | # ANY WARRANTY, to the extent permitted by law; without even the implied | ||
13 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
14 | |||
15 | set -e | ||
16 | set -u | ||
17 | |||
18 | export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' | ||
19 | |||
20 | prefix='/home/plugins' | ||
21 | keep_days=2 | ||
22 | snapshot_dir="$prefix/web/download/snapshot" | ||
23 | repository="$prefix/repositories/nagios-plugins.git" | ||
24 | branches=${*:-'maint master pu'} | ||
25 | myself=${0##*/} | ||
26 | |||
27 | make_dist() | ||
28 | { | ||
29 | version=$1 | ||
30 | |||
31 | tools/setup | ||
32 | ./configure | ||
33 | make dist VERSION="$version" | ||
34 | } | ||
35 | |||
36 | create_snapshot() | ||
37 | { | ||
38 | branch=$1 | ||
39 | snapshot_dir=$2 | ||
40 | |||
41 | git checkout --quiet "$branch" | ||
42 | version=$(git describe --abbrev=4 'HEAD' | sed 's/release-//') | ||
43 | tarball="nagios-plugins-$version.tar.gz" | ||
44 | symlink="nagios-plugins-$branch.tar.gz" | ||
45 | make_dist "$version" | ||
46 | cp "$tarball" "$snapshot_dir" | ||
47 | git reset --quiet --hard | ||
48 | git clean --quiet --force -d -x | ||
49 | |||
50 | cd "$snapshot_dir" | ||
51 | test -e "$tarball.sha1" || shasum -a 1 -b "$tarball" >"$tarball.sha1" | ||
52 | ln -s -f "$tarball" "$symlink" | ||
53 | ln -s -f "$tarball.sha1" "$symlink.sha1" | ||
54 | cd "$OLDPWD" | ||
55 | } | ||
56 | |||
57 | if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] | ||
58 | then | ||
59 | echo "Usage: $myself [branch ...]" | ||
60 | exit 0 | ||
61 | fi | ||
62 | |||
63 | temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX") | ||
64 | log_file="$temp_dir/log" | ||
65 | exec >"$log_file" 3>&2 2>&1 | ||
66 | trap 'tail -n 25 "$log_file" >&3; rm -rf "$temp_dir"' EXIT | ||
67 | set -x | ||
68 | |||
69 | src_dir="$temp_dir/src" | ||
70 | git clone --quiet --shared "$repository" "$src_dir" | ||
71 | cd "$src_dir" | ||
72 | |||
73 | for branch in $branches | ||
74 | do | ||
75 | git show-ref --verify "refs/heads/$branch" \ | ||
76 | && create_snapshot "$branch" "$snapshot_dir" | ||
77 | done | ||
78 | |||
79 | cd "$OLDPWD" | ||
80 | find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -exec rm -f '{}' '+' | ||
81 | find "$snapshot_dir" -type l '!' -exec test -e '{}' ';' -exec rm -f '{}' '+' | ||
82 | trap - EXIT | ||
83 | rm -rf "$temp_dir" | ||