From: Don Armstrong Date: Sat, 5 Nov 2016 03:11:52 +0000 (-0700) Subject: use git with update_spamassassin X-Git-Url: https://git.donarmstrong.com/?p=spamassassin_config.git;a=commitdiff_plain;h=095548a1c0a79b17024a2bb0343907ed922597af;hp=3ef0211eb3435b4041a40d2dabf35e917bfe70d4 use git with update_spamassassin --- diff --git a/update_spamassassin b/update_spamassassin index 46b4952..a8000ab 100755 --- a/update_spamassassin +++ b/update_spamassassin @@ -5,8 +5,6 @@ set -e -SVN=$(which svn) - TMPDIR=$(mktemp -d); HOSTNAME=$(hostname); @@ -23,23 +21,6 @@ else fi; SACONFIG="$BASEDIR/spamassassin_config"; -BAKDIR="$BASEDIR/spamassassin_config_bak"; - -# because alioth continuously fails, make sure that svn info will -# succeed first before cluttering the log. Ideally we would report -# this error, but it happens far too frequently, so we bail out here. -if ! svn info $(svn info $SACONFIG|awk '/^URL:/{print $2}') >/dev/null 2>&1; then - exit 0; -fi; - -# figure out if there's an update to be made -ORIGREV=$(svn info $SACONFIG |awk '/^Revision:/{print $2}') -NEWREV=$(svn info $(svn info $SACONFIG|awk '/^URL:/{print $2}')|awk '/^Revision:/{print $2}') - -# no changes, bug out. -if [ "0$ORIGREV" -ge "0$NEWREV" ]; then - exit 0; -fi; if [ -e "$SACONFIG/.update_spamassassin" ] && kill -0 $(cat "$SACONFIG/.update_spamassassin") >/dev/null 2>&1; then echo "Another update_spamassassin appears to be running" @@ -48,10 +29,22 @@ else echo $$ > "$SACONFIG/.update_spamassassin"; fi; -remove_pidfile () { - rm "$SACONFIG/.update_spamassassin"; +remove_pidfile() { + rm -f "$SACONFIG/.update_spamassassin" } +OLDDIR="$(pwd)"; +cd "$SACONFIG"; +git fetch --all >/dev/null || exit 0; +REMOTE_BRANCH="$(git status --porcelain --branch|grep '^##'|sed 's/.*\.\.\.//')"; +CURRENT_HEAD="$(git rev-parse HEAD)" +REMOTE_BRANCH_HEAD="$(git rev-parse "$REMOTE_BRANCH")" +cd "$OLDDIR"; +## there aren't any updates, stop here. +if [ "$REMOTE_BRANCH_HEAD" = "$CURRENT_HEAD" ]; then + remove_pidfile; + exit 0; +fi; trap remove_pidfile 0; FAILUREMESSAGE=""; @@ -59,9 +52,10 @@ report_failure () { # Hrm; a previous update failed; don't report again until the file # is removed or it's more than a day old if [ -e "$SACONFIG/failed_update" ] && - [ $(($(date +%s) - $(stat -c '%Y' "$SACONFIG/failed_update"))) -lt 86400 ]; then - rm -rf "$TMPDIR" - exit 0; + [ $(($(date +%s) - $(stat -c '%Y' "$SACONFIG/failed_update"))) -lt 86400 ]; then + rm -rf "$TMPDIR"; + remove_pidfile; + exit 0; fi; echo "$FAILUREMESSAGE" > "$SACONFIG/failed_update" echo "$FAILUREMESSAGE"; @@ -73,27 +67,25 @@ updates will not occur until this is fixed. Please fix the problem and then remove $SACONFIG/failed_update EOF - rm -rf "$TMPDIR" + remove_pidfile; + rm -rf "$TMPDIR"; exit 1; } -cp -ar $SACONFIG $TMPDIR/. -OLDDIR="$(pwd)" +cp -ar $SACONFIG $TMPDIR/.; +OLDDIR="$(pwd)"; cd $TMPDIR/spamassassin_config; -svn update -q --non-interactive; -if svn status |grep -q '^C'; then - FAILUREMESSAGE=$'The following conflicts were found\n\n' - FAILUREMESSAGE="$FAILUREMESSAGE$(svn status|grep ^C)"; - report_failure +if ! git merge --quiet --ff-only $REMOTE_BRANCH; then + FAILUREMESSAGE="The update from $REMOTE_BRANCH to $REMOTE_BRANCH_HEAD\nis not a fast-forward\n\n" + report_failure; fi; -cd "$(pwd)" if ! spamassassin -p $TMPDIR/spamassassin_config/$USERCONF --lint > $TMPDIR/sa_lint 2>&1; then FAILUREMESSAGE="$(echo -e 'spamassassin -p $TMPDIR/spamassassin_config/$USERCONF --lint\nfailed with\n'| cat - $TMPDIR/sa_lint)"; report_failure fi; -mv "$SACONFIG" "$BAKDIR/spamassassin_config_r$ORIGREV" -mv "$TMPDIR/spamassassin_config" "$SACONFIG" +cd "$SACONFIG": +git merge --ff-only $REMOTE_BRANCH --quiet; trap - 0 remove_pidfile rm -rf "$TMPDIR"