summaryrefslogtreecommitdiffstats
path: root/bin/build-snapshot
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2014-01-25 18:32:30 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2014-01-25 18:32:30 (GMT)
commitab5d4e5051e3721096bbee4653293ec30884e53b (patch)
tree21756771f6461f63710b45ce135ed8148cceb1e8 /bin/build-snapshot
parentae3917c571d4390d7eb46fdea95146ff21144941 (diff)
downloadsite-ab5d4e5051e3721096bbee4653293ec30884e53b.tar.gz
"build-snapshot" -> "build-snapshots"
The script can build the snapshots for multiple branches in one go (and does that by default).
Diffstat (limited to 'bin/build-snapshot')
-rwxr-xr-xbin/build-snapshot114
1 files changed, 0 insertions, 114 deletions
diff --git a/bin/build-snapshot b/bin/build-snapshot
deleted file mode 100755
index 4c016c5..0000000
--- a/bin/build-snapshot
+++ /dev/null
@@ -1,114 +0,0 @@
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/monitoring-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 if git show-ref --verify --quiet "refs/heads/$branch"
42 then
43 git checkout --quiet "$branch"
44 else
45 git checkout --quiet --track "origin/$branch"
46 fi
47
48 version=$(git describe --abbrev=4 'HEAD' | sed 's/release-//')
49 tarball="monitoring-plugins-$version.tar.gz"
50 symlink="monitoring-plugins-$branch.tar.gz"
51
52 if [ ! -e "$snapshot_dir/$tarball" ]
53 then
54 make_dist "$version"
55 cp "$tarball" "$snapshot_dir"
56 git reset --quiet --hard
57 git clean --quiet --force -d -x
58 fi
59 cd "$snapshot_dir"
60 test -e "$tarball.sha1" || shasum -a 1 -b "$tarball" >"$tarball.sha1"
61 ln -s -f "$tarball" "$symlink"
62 ln -s -f "$tarball.sha1" "$symlink.sha1"
63 cd "$OLDPWD"
64}
65
66rm_old_snapshots()
67{
68 snapshot_dir=$1
69 keep_days=$2
70 link_targets=$(find "$snapshot_dir" -type l -exec readlink '{}' ';')
71
72 find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -print \
73 | while read file
74 do
75 referenced=0
76
77 for link_target in $link_targets
78 do
79 if [ "$link_target" = "${file##*/}" ]
80 then
81 referenced=1
82 break
83 fi
84 done
85 test $referenced -eq 1 || rm -f "$file"
86 done
87}
88
89if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ]
90then
91 echo "Usage: $myself [branch ...]"
92 exit 0
93fi
94
95temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX")
96log_file="$temp_dir/log"
97exec >"$log_file" 3>&2 2>&1
98trap 'tail -n 25 "$log_file" >&3; rm -rf "$temp_dir"' EXIT
99set -x
100
101src_dir="$temp_dir/src"
102git clone --quiet --shared --no-checkout "$repository" "$src_dir"
103cd "$src_dir"
104
105for branch in $branches
106do
107 git show-ref --verify "refs/remotes/origin/$branch" \
108 && create_snapshot "$branch" "$snapshot_dir"
109done
110
111cd "$OLDPWD"
112rm_old_snapshots "$snapshot_dir" "$keep_days"
113trap - EXIT
114rm -rf "$temp_dir"