* Add update_spamassassin script which will enable the spamassassin
authorDon Armstrong <don@debian.org>
Tue, 23 Oct 2007 07:26:56 +0000 (07:26 +0000)
committerDon Armstrong <don@debian.org>
Tue, 23 Oct 2007 07:26:56 +0000 (07:26 +0000)
  configuration to be updated automatically. [Still needs testing]

git-svn-id: svn+ssh://svn.debian.org/svn/pkg-listmaster/trunk/spamassassin_config@75 0b7a5b0c-1f2c-0410-bd74-c376f8064c91

update_spamassassin [new file with mode: 0755]

diff --git a/update_spamassassin b/update_spamassassin
new file mode 100755 (executable)
index 0000000..1a8c41a
--- /dev/null
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+# This command updates the spamassassin configuration; tests the new
+# configuration; then moves the updated configuration in place
+
+set -e
+
+SVN=$(which svn)
+
+TMPDIR=$(mktemp -d);
+
+if [ "$HOSTNAME" == "rietz" ]; then
+    BASEDIR="/org/bugs.debian.org"
+    USERCONF="bugs/user_prefs";
+elif [ "$HOSTNAME" == "murphy" ]; then
+    BASEDIR="/var/list/.etc";
+    USERCONF="bugs/user_prefs";
+else
+    echo "Unknown hostname '$HOSTNAME'";
+    exit 1;
+fi;
+
+SACONFIG="$BASEDIR/spamassassin_config";
+BAKDIR="$BASEDIR/spamassassin_config_bak";
+
+# 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 [ $ORIGREV -ge $NEWREV ];
+    exit 0;
+fi;
+
+if [ -e "$SACONFIG/.update_spamassassin" ] && kill -0 $(cat "$SACONFIG/.update_spamassassin"); then
+    echo "Another update_spamassassin appears to be running"
+    exit 1;
+else
+    echo $$ > "$SACONFIG/.update_spamassassin";
+fi;
+
+function remove_pidfile(){
+    rm "$SACONFIG/.update_spamassassin";
+}
+
+trap remove_pidfile ERR;
+
+FAILUREMESSAGE="";
+function report_failure(){
+    # Hrm; a previous update failed; don't report again until the file
+    # is removed
+    if [ -e "$SACONFIG/failed_update" ]; then
+       exit 0;
+    fi;
+    echo "$FAILURE_MESSAGE" >> "$SACONFIG/failed_update"
+    echo "$FAILURE_MESSAGE";
+    echo
+    echo "update_spamassassin will not report any additional errors until this is fixed"
+    exit 1;
+}
+
+cp -ar $SACONFIG $TMPDIR/.
+cd $TMPDIR/spamassassin_config;
+svn update -q --non-interactive; 
+if svn status |grep -q '^C'; then
+    FAILUREMESSAGE="$(echo -e 'The following conflicts were found\n')"
+    FAILUREMESSAGE="$FAILUREMESSAGE$(svn status|grep ^C)";
+    report_failure
+fi;
+cd - >/dev/null 2>&1
+
+FAILUREMESSAGE="$(spamassassin -C $TMPDIR/spamassassin_config/$USERCONF --lint)"
+if [ "$?" != "0" ]; then
+    FAILUREMESSAGE="$(echo -e 'spamassassin -C $TMPDIR/spamassassin_config/$USERCONF --lint\nfailed with\n')$FAILUREMESSAGE";
+    report_failure
+fi;
+mv "$SACONFIG" "$BAKDIR/spamassassin_config_r$ORIGREV"
+mv "$TMPDIR/spamassassin_config" "$SACONFIG"
+trap ERR
+rm -rf "$TMPDIR"
+
+if [ "$HOSTNAME" == "rietz" ]; then
+    touch /home/debbugs/.spamassassin/user_prefs
+elif [ "$HOSTNAME" == "murphy" ]; then
+    # do nothing
+else
+    echo "Unknown hostname '$HOSTNAME'";
+    exit 1;
+fi;
+
+
+exit 0;
\ No newline at end of file