]> git.donarmstrong.com Git - spamassassin_config.git/blobdiff - update_spamassassin
Block https://lists.debian.org/debian-www/2015/05/msg00070.html and others
[spamassassin_config.git] / update_spamassassin
index b5641365f21023ba73d728debfd7e00731e9c632..46b4952357d5838ebb75e37213b89911971909d2 100755 (executable)
@@ -9,10 +9,12 @@ SVN=$(which svn)
 
 TMPDIR=$(mktemp -d);
 
-if [ "$HOSTNAME" == "rietz" ]; then
+HOSTNAME=$(hostname);
+
+if [ "$HOSTNAME" = "buxtehude" ]; then
     BASEDIR="/org/bugs.debian.org"
     USERCONF="bugs/user_prefs";
-elif [ "$HOSTNAME" == "liszt" ]; then
+elif [ "$HOSTNAME" = "bendel" ]; then
     BASEDIR="/var/list/.etc";
     USERCONF="lists/user_prefs";
 else
@@ -23,12 +25,19 @@ 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 [ $ORIGREV -ge $NEWREV ]; then
+if [ "0$ORIGREV" -ge "0$NEWREV" ]; then
     exit 0;
 fi;
 
@@ -39,33 +48,37 @@ else
     echo $$ > "$SACONFIG/.update_spamassassin";
 fi;
 
-function remove_pidfile(){
+remove_pidfile () {
     rm "$SACONFIG/.update_spamassassin";
 }
 
-trap remove_pidfile ERR;
+trap remove_pidfile 0;
 
 FAILUREMESSAGE="";
-function report_failure(){
+report_failure () {
     # Hrm; a previous update failed; don't report again until the file
-    # is removed
-    if [ -e "$SACONFIG/failed_update" ]; then
+    # 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;
     fi;
-    echo "$FAILUREMESSAGE" >> "$SACONFIG/failed_update"
+    echo "$FAILUREMESSAGE" > "$SACONFIG/failed_update"
     echo "$FAILUREMESSAGE";
     cat - <<EOF;
 
-Update_spamassassin will not report any additional errors until this
-is fixed.
+update_spamassassin will only report this error once a day, and
+updates will not occur until this is fixed.
 
 Please fix the problem and then remove
 $SACONFIG/failed_update
 EOF
+    rm -rf "$TMPDIR"
     exit 1;
 }
 
 cp -ar $SACONFIG $TMPDIR/.
+OLDDIR="$(pwd)"
 cd $TMPDIR/spamassassin_config;
 svn update -q --non-interactive; 
 if svn status |grep -q '^C'; then
@@ -73,7 +86,7 @@ if svn status |grep -q '^C'; then
     FAILUREMESSAGE="$FAILUREMESSAGE$(svn status|grep ^C)";
     report_failure
 fi;
-cd - >/dev/null 2>&1
+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)";
@@ -81,13 +94,13 @@ if ! spamassassin -p $TMPDIR/spamassassin_config/$USERCONF --lint > $TMPDIR/sa_l
 fi;
 mv "$SACONFIG" "$BAKDIR/spamassassin_config_r$ORIGREV"
 mv "$TMPDIR/spamassassin_config" "$SACONFIG"
-trap - ERR
+trap - 0
 remove_pidfile
 rm -rf "$TMPDIR"
 
-if [ "$HOSTNAME" == "rietz" ]; then
+if [ "$HOSTNAME" = "buxtehude" ]; then
     touch /home/debbugs/.spamassassin/user_prefs
-elif [ "$HOSTNAME" == "liszt" ]; then
+elif [ "$HOSTNAME" = "bendel" ]; then
     # do nothing
     true;
 else