summaryrefslogtreecommitdiffstats
path: root/tools/git-update-mirror
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2009-10-24 09:42:52 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2009-10-24 09:42:52 (GMT)
commit7f1844835dac4df2e8fe98d72d6fe77d5117eb2e (patch)
tree0e189e4441cd237d9a13e5b01332174e2a7547a2 /tools/git-update-mirror
parente7e9a99117d7e0a7189393b3a04366393620efab (diff)
downloadmonitoring-plugins-7f1844835dac4df2e8fe98d72d6fe77d5117eb2e.tar.gz
Import git-update-mirror and git-notify
Import the (self-written) git-update-mirror script, which updates clones of Git repositories and then calls git-notify (in just the same way as a post-receive hook would be called by Git). The git-notify script is imported from git://source.winehq.org/git/tools.git (commit: 03d66f34) and generates notifications on repository changes. We'll use these scripts for generating our commit e-mails.
Diffstat (limited to 'tools/git-update-mirror')
-rwxr-xr-xtools/git-update-mirror94
1 files changed, 94 insertions, 0 deletions
diff --git a/tools/git-update-mirror b/tools/git-update-mirror
new file mode 100755
index 0000000..1c6eea5
--- /dev/null
+++ b/tools/git-update-mirror
@@ -0,0 +1,94 @@
1#!/bin/sh
2#
3# Copyright (c) 2009 Nagios Plugins Development Team
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18set -e
19set -u
20
21prefix='/home/git'
22
23PATH="$prefix/opt/git/bin:/bin:/usr/bin"
24export PATH
25
26gitnotify="$prefix/libexec/git-notify"
27recipient='Nagios Plugins Commit List <nagiosplug-checkins@lists.sourceforge.net>'
28maxcommits=100
29maxdiffsize=$((300 * 1024))
30gitweburl='http://repo.or.cz/w'
31tempprefix='/dev/shm'
32fourtyzeros=$(printf '%.40u' 0)
33myself=${0##*/}
34
35checkrefs()
36{
37 turn=$1
38
39 git show-ref | while read object ref
40 do
41 refdir="$tempdir/${ref%/*}"
42 reffile="$tempdir/$ref"
43
44 if [ $turn -eq 2 -a -f "$reffile" ] \
45 && grep "^1 $object$" "$reffile" >'/dev/null'
46 then # The ref has not been modified.
47 rm -f "$reffile"
48 else
49 mkdir -p "$refdir"
50 echo "$turn $object" >>"$reffile"
51 fi
52 done
53}
54
55if [ $# -lt 1 ]
56then
57 echo >&2 "Usage: $myself <repository> ..."
58 exit 1
59fi
60
61tempdir=$(mktemp -d "$tempprefix/$myself.XXXXXX")
62tempfile=$(mktemp "$tempprefix/$myself.XXXXXX")
63trap 'rm -rf "$tempdir" "$tempfile"' EXIT
64
65for repository in "$@"
66do
67 cd "$repository"
68
69 checkrefs 1
70 if ! git remote update --prune >"$tempfile" 2>&1
71 then
72 cat >&2 "$tempfile"
73 exit 1
74 fi
75 git fetch --quiet --tags
76 checkrefs 2
77
78 find "$tempdir" -type 'f' -print | sed 's!^\./!!' | while read reffile
79 do
80 ref=${reffile#$tempdir/}
81 old=$(awk '$1 == "1" { print $2; exit }' "$reffile")
82 new=$(awk '$1 == "2" { print $2; exit }' "$reffile")
83 old=${old:-$fourtyzeros}
84 new=${new:-$fourtyzeros}
85
86 echo "$old" "$new" "$ref"
87 done | $gitnotify \
88 -m "$recipient" \
89 -n "$maxcommits" \
90 -s "$maxdiffsize" \
91 -u "$gitweburl"
92
93 cd "$OLDPWD"
94done