diff options
Diffstat (limited to 'bin/build-snapshots')
| -rwxr-xr-x | bin/build-snapshots | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/bin/build-snapshots b/bin/build-snapshots new file mode 100755 index 0000000..4c016c5 --- /dev/null +++ b/bin/build-snapshots | |||
| @@ -0,0 +1,114 @@ | |||
| 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/monitoring-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 | 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 | |||
| 66 | rm_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 | |||
| 89 | if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] | ||
| 90 | then | ||
| 91 | echo "Usage: $myself [branch ...]" | ||
| 92 | exit 0 | ||
| 93 | fi | ||
| 94 | |||
| 95 | temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX") | ||
| 96 | log_file="$temp_dir/log" | ||
| 97 | exec >"$log_file" 3>&2 2>&1 | ||
| 98 | trap 'tail -n 25 "$log_file" >&3; rm -rf "$temp_dir"' EXIT | ||
| 99 | set -x | ||
| 100 | |||
| 101 | src_dir="$temp_dir/src" | ||
| 102 | git clone --quiet --shared --no-checkout "$repository" "$src_dir" | ||
| 103 | cd "$src_dir" | ||
| 104 | |||
| 105 | for branch in $branches | ||
| 106 | do | ||
| 107 | git show-ref --verify "refs/remotes/origin/$branch" \ | ||
| 108 | && create_snapshot "$branch" "$snapshot_dir" | ||
| 109 | done | ||
| 110 | |||
| 111 | cd "$OLDPWD" | ||
| 112 | rm_old_snapshots "$snapshot_dir" "$keep_days" | ||
| 113 | trap - EXIT | ||
| 114 | rm -rf "$temp_dir" | ||
