-
Notifications
You must be signed in to change notification settings - Fork 0
/
svn-check-rev.sh
executable file
·114 lines (99 loc) · 2.5 KB
/
svn-check-rev.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash -e
#
# Checks for available Subversion updates
#
# - Notifications are optionally send via Growl (growlnotify)
#
# Take care to edit the variables as neccessary!
#
# Author: Jan Beilicke <[email protected]>
# Created: 2010-06-10
# Last modified: 2010-06-29
#
# -------------------------------------------------------------------
#
# Usage: svn-check-rev.sh [-h] [-n] [-s] /path/to/svn/working/copy/
# Parameters:
# -h Display help
# -n Use Growl to notify about updates (requires 'growlnotify' in \$PATH)
# -s Sticky growl notification (automatically enables Growl)
#
### General ###
PATH="/usr/bin:/opt/local/bin:/usr/local/bin:${PATH}"
NOTIFIER=`which growlnotify`
SVN=`which svn`
##### Do not edit anything below this line! #####
USEGROWL=false
STICKY=false
E_BADARGS=65
usage() {
cat <<EOF
Usage: `basename $0` [-h] [-n] [-s] /path/to/svn/working/copy/
Parameters:
-h Display this help
-n Use Growl to notify about updates (requires 'growlnotify' in \$PATH)
-s Sticky growl notification (automatically enables Growl)
EOF
}
while getopts "hnsd:" ARG; do
case "${ARG}" in
h )
usage
exit 1
;;
n )
if [[ ! -e "$NOTIFIER" ]]; then
echo "Growl not found. Continuing without it ..."
USEGROWL=false
else
USEGROWL=true
fi
;;
s )
if [[ ! -e "$NOTIFIER" ]]; then
echo "Growl not found. Continuing without it ..."
USEGROWL=false
STICKY=false
else
USEGROWL=true
STICKY=true
fi
;;
? )
usage
exit 1
;;
* )
echo
echo "Unkown error while processing parameters."
exit 1
esac
done
if [[ ! -d "${!#}" ]]; then
echo
echo "Last argument isn't a directory or doesn't exist."
usage
exit 1
fi
SVNWCPATH="${!#}"
[[ "$STICKY" = true ]] && SETSTICKY="-s"
SVNURL=`$SVN info $SVNWCPATH | awk '/URL:/ {print $2}'`
LOCALREV=`$SVN info $SVNWCPATH | awk '/Last Changed Rev:/ {print $4}'`
REMOTEREV=`$SVN info -rHEAD $SVNWCPATH | awk '/Last Changed Rev:/ {print $4}'`
echo
echo "URL: $SVNURL"
echo "Local revision: $LOCALREV"
echo "Remote revision: $REMOTEREV"
DIFFREV=$((REMOTEREV - LOCALREV))
if [[ "$DIFFREV" -gt 0 ]]; then
if [[ "$USEGROWL" = true ]] && [[ -e "$NOTIFIER" ]]; then
"$NOTIFIER" "$SETSTICKY" -d "$SVNURL" -m "${SVNURL##*/}: Updates available! Remote rev. is $REMOTEREV (local rev. $LOCALREV)"
fi
echo
echo "Updates available!"
else
echo
echo "No updates available."
fi
echo
exit 0