summaryrefslogtreecommitdiffstats
path: root/bin/build-snapshot
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-09-29 22:03:24 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-09-29 22:03:24 (GMT)
commit0b6423f9c99d9edf8c96fefd0f6c453859395aa1 (patch)
tree1c2b6b21704a294940f87c7892676998d8371707 /bin/build-snapshot
downloadsite-0b6423f9c99d9edf8c96fefd0f6c453859395aa1.tar.gz
Import Nagios Plugins site
Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files.
Diffstat (limited to 'bin/build-snapshot')
-rwxr-xr-xbin/build-snapshot83
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
15set -e
16set -u
17
18export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin'
19
20prefix='/home/plugins'
21keep_days=2
22snapshot_dir="$prefix/web/download/snapshot"
23repository="$prefix/repositories/nagios-plugins.git"
24branches=${*:-'maint master pu'}
25myself=${0##*/}
26
27make_dist()
28{
29 version=$1
30
31 tools/setup
32 ./configure
33 make dist VERSION="$version"
34}
35
36create_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
57if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ]
58then
59 echo "Usage: $myself [branch ...]"
60 exit 0
61fi
62
63temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX")
64log_file="$temp_dir/log"
65exec >"$log_file" 3>&2 2>&1
66trap 'tail -n 25 "$log_file" >&3; rm -rf "$temp_dir"' EXIT
67set -x
68
69src_dir="$temp_dir/src"
70git clone --quiet --shared "$repository" "$src_dir"
71cd "$src_dir"
72
73for branch in $branches
74do
75 git show-ref --verify "refs/heads/$branch" \
76 && create_snapshot "$branch" "$snapshot_dir"
77done
78
79cd "$OLDPWD"
80find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -exec rm -f '{}' '+'
81find "$snapshot_dir" -type l '!' -exec test -e '{}' ';' -exec rm -f '{}' '+'
82trap - EXIT
83rm -rf "$temp_dir"