-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-watch.sh
executable file
·73 lines (61 loc) · 1.29 KB
/
git-watch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
if [ -z "${1+x}" ]; then
echo "no args, exiting"
exit 1
fi
CONFIGURATION_DIRECTORY=${CONFIGURATION_DIRECTORY:=$PWD}
CACHE_DIRECTORY=${CACHE_DIRECTORY:=/var/cache/git-watch}
NAME=$1
CFG="$CONFIGURATION_DIRECTORY"/"$NAME"
CLONEDIR="$CACHE_DIRECTORY"/"$NAME"/git
if [ ! -f "$CFG" ]; then
echo "Configuration file '$CFG' not found, exiting"
exit 1
fi
source "$CFG"
if [ -z "${GITSRC+x}" ]; then
echo "GITSRC is not set, exiting"
exit 1
fi
if [ ! -d "$GITSRC" ]; then
echo "GITSRC is not a directory, exiting"
exit 1
fi
if [ -z "${GITCMD+x}" ]; then
echo "GITCMD is not set, exiting"
exit 1
fi
mkdir -p "$CACHE_DIRECTORY"/"$NAME" || exit 1
while true
do
if [ ! -d "$CLONEDIR" ]; then
git clone "$GITSRC" "$CLONEDIR" || exit 1
else
cd "$CLONEDIR" || exit 1
git fetch --all || exit 1
git reset --hard origin/master || exit 1
fi
cd "$CLONEDIR" || exit 1
git log -n1 "$CLONEDIR"
OUT=$(mktemp -t "git-watch-$NAME-out.XXXXXX")
ERR=$(mktemp -t "git-watch-$NAME-err.XXXXXX")
if $GITCMD >"$OUT" 2>"$ERR" ; then
echo success
echo STDOUT:
cat "$OUT"
echo ---
echo STDERR:
cat "$ERR"
echo ---
else
echo error
echo STDOUT:
cat "$OUT"
echo ---
echo STDERR:
cat "$ERR"
echo ---
fi
rm -f "$OUT" "$ERR"
inotifywait "$GITSRC"/.git/refs/heads/master
done