#!/bin/sh # This command updates the spamassassin configuration; tests the new # configuration; then moves the updated configuration in place set -e TMPDIR=$(mktemp -d); HOSTNAME=$(hostname); if [ "$HOSTNAME" = "buxtehude" ]; then BASEDIR="/org/bugs.debian.org" USERCONF="bugs/user_prefs"; elif [ "$HOSTNAME" = "bendel" ]; then BASEDIR="/var/list/.etc"; USERCONF="lists/user_prefs"; else echo "Unknown hostname '$HOSTNAME'"; exit 1; fi; SACONFIG="$BASEDIR/spamassassin_config"; if [ -e "$SACONFIG/.update_spamassassin" ] && kill -0 $(cat "$SACONFIG/.update_spamassassin") >/dev/null 2>&1; then echo "Another update_spamassassin appears to be running" exit 1; else echo $$ > "$SACONFIG/.update_spamassassin"; fi; 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=""; 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"; remove_pidfile; exit 0; fi; echo "$FAILUREMESSAGE" > "$SACONFIG/failed_update" echo "$FAILUREMESSAGE"; cat - < $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; cd "$SACONFIG": git merge --ff-only $REMOTE_BRANCH --quiet; trap - 0 remove_pidfile rm -rf "$TMPDIR" if [ "$HOSTNAME" = "buxtehude" ]; then touch /home/debbugs/.spamassassin/user_prefs elif [ "$HOSTNAME" = "bendel" ]; then # do nothing true; else echo "Unknown hostname '$HOSTNAME'"; exit 1; fi; exit 0;