From ab5d4e5051e3721096bbee4653293ec30884e53b Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sat, 25 Jan 2014 19:32:30 +0100 Subject: "build-snapshot" -> "build-snapshots" The script can build the snapshots for multiple branches in one go (and does that by default). 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 @@ -#!/bin/sh -# -# Copyright (c) 2013 Nagios Plugins Development Team -# -# Originally written by Holger Weiss . -# -# This file is free software; the Nagios Plugins Development Team gives -# unlimited permission to copy and/or distribute it, with or without -# modifications, as long as this notice is preserved. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY, to the extent permitted by law; without even the implied -# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -set -e -set -u - -export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' - -prefix='/home/plugins' -keep_days=2 -snapshot_dir="$prefix/web/download/snapshot" -repository="$prefix/repositories/monitoring-plugins.git" -branches=${*:-'maint master pu'} -myself=${0##*/} - -make_dist() -{ - version=$1 - - tools/setup - ./configure - make dist VERSION="$version" -} - -create_snapshot() -{ - branch=$1 - snapshot_dir=$2 - - if git show-ref --verify --quiet "refs/heads/$branch" - then - git checkout --quiet "$branch" - else - git checkout --quiet --track "origin/$branch" - fi - - version=$(git describe --abbrev=4 'HEAD' | sed 's/release-//') - tarball="monitoring-plugins-$version.tar.gz" - symlink="monitoring-plugins-$branch.tar.gz" - - if [ ! -e "$snapshot_dir/$tarball" ] - then - make_dist "$version" - cp "$tarball" "$snapshot_dir" - git reset --quiet --hard - git clean --quiet --force -d -x - fi - cd "$snapshot_dir" - test -e "$tarball.sha1" || shasum -a 1 -b "$tarball" >"$tarball.sha1" - ln -s -f "$tarball" "$symlink" - ln -s -f "$tarball.sha1" "$symlink.sha1" - cd "$OLDPWD" -} - -rm_old_snapshots() -{ - snapshot_dir=$1 - keep_days=$2 - link_targets=$(find "$snapshot_dir" -type l -exec readlink '{}' ';') - - find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -print \ - | while read file - do - referenced=0 - - for link_target in $link_targets - do - if [ "$link_target" = "${file##*/}" ] - then - referenced=1 - break - fi - done - test $referenced -eq 1 || rm -f "$file" - done -} - -if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] -then - echo "Usage: $myself [branch ...]" - exit 0 -fi - -temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX") -log_file="$temp_dir/log" -exec >"$log_file" 3>&2 2>&1 -trap 'tail -n 25 "$log_file" >&3; rm -rf "$temp_dir"' EXIT -set -x - -src_dir="$temp_dir/src" -git clone --quiet --shared --no-checkout "$repository" "$src_dir" -cd "$src_dir" - -for branch in $branches -do - git show-ref --verify "refs/remotes/origin/$branch" \ - && create_snapshot "$branch" "$snapshot_dir" -done - -cd "$OLDPWD" -rm_old_snapshots "$snapshot_dir" "$keep_days" -trap - EXIT -rm -rf "$temp_dir" 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 @@ +#!/bin/sh +# +# Copyright (c) 2013 Nagios Plugins Development Team +# +# Originally written by Holger Weiss . +# +# This file is free software; the Nagios Plugins Development Team gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY, to the extent permitted by law; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +set -e +set -u + +export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' + +prefix='/home/plugins' +keep_days=2 +snapshot_dir="$prefix/web/download/snapshot" +repository="$prefix/repositories/monitoring-plugins.git" +branches=${*:-'maint master pu'} +myself=${0##*/} + +make_dist() +{ + version=$1 + + tools/setup + ./configure + make dist VERSION="$version" +} + +create_snapshot() +{ + branch=$1 + snapshot_dir=$2 + + if git show-ref --verify --quiet "refs/heads/$branch" + then + git checkout --quiet "$branch" + else + git checkout --quiet --track "origin/$branch" + fi + + version=$(git describe --abbrev=4 'HEAD' | sed 's/release-//') + tarball="monitoring-plugins-$version.tar.gz" + symlink="monitoring-plugins-$branch.tar.gz" + + if [ ! -e "$snapshot_dir/$tarball" ] + then + make_dist "$version" + cp "$tarball" "$snapshot_dir" + git reset --quiet --hard + git clean --quiet --force -d -x + fi + cd "$snapshot_dir" + test -e "$tarball.sha1" || shasum -a 1 -b "$tarball" >"$tarball.sha1" + ln -s -f "$tarball" "$symlink" + ln -s -f "$tarball.sha1" "$symlink.sha1" + cd "$OLDPWD" +} + +rm_old_snapshots() +{ + snapshot_dir=$1 + keep_days=$2 + link_targets=$(find "$snapshot_dir" -type l -exec readlink '{}' ';') + + find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -print \ + | while read file + do + referenced=0 + + for link_target in $link_targets + do + if [ "$link_target" = "${file##*/}" ] + then + referenced=1 + break + fi + done + test $referenced -eq 1 || rm -f "$file" + done +} + +if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] +then + echo "Usage: $myself [branch ...]" + exit 0 +fi + +temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX") +log_file="$temp_dir/log" +exec >"$log_file" 3>&2 2>&1 +trap 'tail -n 25 "$log_file" >&3; rm -rf "$temp_dir"' EXIT +set -x + +src_dir="$temp_dir/src" +git clone --quiet --shared --no-checkout "$repository" "$src_dir" +cd "$src_dir" + +for branch in $branches +do + git show-ref --verify "refs/remotes/origin/$branch" \ + && create_snapshot "$branch" "$snapshot_dir" +done + +cd "$OLDPWD" +rm_old_snapshots "$snapshot_dir" "$keep_days" +trap - EXIT +rm -rf "$temp_dir" diff --git a/libexec/post-receive.d/02-build-snapshots b/libexec/post-receive.d/02-build-snapshots index 578c071..ca06043 100755 --- a/libexec/post-receive.d/02-build-snapshots +++ b/libexec/post-receive.d/02-build-snapshots @@ -31,7 +31,7 @@ then for snapshot_branch in $snapshot_branches do test "$branch" = "$snapshot_branch" \ - && "$prefix/bin/build-snapshot" "$branch" + && "$prefix/bin/build-snapshots" "$branch" done done fi -- cgit v0.10-9-g596f