Skip to content

Instantly share code, notes, and snippets.

@pix0r
Created May 4, 2010 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pix0r/389816 to your computer and use it in GitHub Desktop.
Save pix0r/389816 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Installation: Make svn-growlnotify.sh executable (chmod +x svn-growlnotify.sh) and
# add an entry to your crontab similar to:
# * * * * * /path/to/svn-growlnotify.sh -s https://your.repository.url/ 1>/dev/null 2>&1
#
# Usage: svn-growlnotify.sh -s <SVN_ROOT> [-l LOG_URL] [-r REV_FILE] [-m MAX_REVS] [-g GROWLNOTIFY]
#
# Default settings
SVN_ROOT=""
LOG_URL=""
REV_FILE="$HOME/.svn-growlnotify.version"
MAX_REVS="5"
GROWLNOTIFY="/usr/local/bin/growlnotify"
# Program
while getopts "s:l:r:m:g:" flag; do
case "$flag" in
s) SVN_ROOT=$OPTARG;;
l) LOG_URL=$OPTARG;;
r) REV_FILE=$OPTARG;;
m) MAX_REVS=$OPTARG;;
g) GROWLNOTIFY=$OPTARG;;
esac
done
if [ "$SVN_ROOT" = "" ]; then
echo "Usage: $0 -s <SVN_ROOT> [-l LOG_URL] [-r REV_FILE] [-m MAX_REVS] [-g GROWLNOTIFY]"
exit 1
fi
SVN_REV=`svn log $SVN_ROOT --limit 1 | awk '/^r/ {print $1}' | sed 's/[^0-9]//g'`
LAST_REV=`cat $REV_FILE 2>/dev/null`
if [ "$LAST_REV" = "" ]; then
LAST_REV=0
fi
NUM_REVS=`echo $SVN_REV - $LAST_REV | bc`
echo "SVN Revision: $SVN_REV"
echo "Last Revision: $LAST_REV"
echo "Num Revs: $NUM_REVS"
if [ $NUM_REVS -gt $MAX_REVS ]; then
NUM_REVS=$MAX_REVS
echo "Decreased num revs max: $MAX_REVS"
fi
if [ $NUM_REVS = 0 ]; then
exit
fi
START_REV=`echo $SVN_REV - $NUM_REVS + 1 | bc`
for rev in `jot $NUM_REVS $START_REV`; do
IFS_SAV=$IFS
IFS=''
SHORT=`svn log -r$rev $SVN_ROOT | grep -v -- -----`
MSG_LINES=`echo $SHORT | head -1 | awk ' { print $13 } '`
MSG=`echo -e $SHORT | tail -$MSG_LINES`
USER=`echo $SHORT | awk ' { print $3 } ' | head -1`
DATE=`echo $SHORT | awk ' { print $5 " " $6 " " $7 } ' | head -1`
LONG=`svn log -v -r$rev $SVN_ROOT | grep -v -- -----`
if [ "$MSG" = "" ]; then
MSG_LINES=0
fi
TOTAL_LINES=`echo $LONG | wc -l`
TOTAL_WITHOUT_MSG=`echo $TOTAL_LINES - $MSG_LINES | bc`
CHANGE_LINES=`echo $TOTAL_WITHOUT_MSG - 2 | bc`
CHANGES=`echo $LONG | head -$TOTAL_WITHOUT_MSG | tail -$CHANGE_LINES`
BODY="r$rev by $USER
$MSG
$CHANGES"
echo $BODY | $GROWLNOTIFY "SVN Update $rev"
done
echo $SVN_REV > $REV_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment