From 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 30 Sep 2013 00:03:24 +0200 Subject: Import Nagios Plugins site Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files. --- bin/git-mirror | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 bin/git-mirror (limited to 'bin/git-mirror') diff --git a/bin/git-mirror b/bin/git-mirror new file mode 100755 index 0000000..af54a14 --- /dev/null +++ b/bin/git-mirror @@ -0,0 +1,84 @@ +#!/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' + +temp_prefix='/run/shm' +fourty_zeros=$(printf '%.40u' 0) +myself=${0##*/} + +check_refs() +{ + turn=$1 + temp_dir=$2 + + git show-ref | while read object ref + do + ref_dir="$temp_dir/${ref%/*}" + ref_file="$temp_dir/$ref" + + if [ $turn -eq 2 -a -f "$ref_file" ] \ + && grep "^1 $object$" "$ref_file" >'/dev/null' + then # The ref has not been modified. + rm -f "$ref_file" + else + mkdir -p "$ref_dir" + echo "$turn $object" >>"$ref_file" + fi + done +} + +if [ $# -lt 1 ] +then + echo >&2 "Usage: $myself ..." + exit 2 +fi + +temp_dir=$(mktemp -d "$temp_prefix/$myself.XXXXXX") +temp_file=$(mktemp "$temp_prefix/$myself.XXXXXX") +trap 'rm -rf "$temp_dir" "$temp_file"' EXIT + +for repository in "$@" +do + hook="$repository/hooks/post-receive" + cd "$repository" + + check_refs 1 "$temp_dir" + if ! git remote update --prune >"$temp_file" 2>&1 + then + cat >&2 "$temp_file" + exit 1 + fi + git fetch --quiet --tags + check_refs 2 "$temp_dir" + + if [ -x "$hook" ] + then + find "$temp_dir" -type 'f' -print | while read ref_file + do + ref=${ref_file#$temp_dir/} + old=$(awk '$1 == "1" { print $2; exit }' "$ref_file") + new=$(awk '$1 == "2" { print $2; exit }' "$ref_file") + old=${old:-$fourty_zeros} + new=${new:-$fourty_zeros} + + echo "$old" "$new" "$ref" + done >"$temp_file" + test -s "$temp_file" && "$hook" <"$temp_file" + fi + cd "$OLDPWD" +done -- cgit v1.2.3-74-g34f1