update_spamassassin 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/sh
  2. # This command updates the spamassassin configuration; tests the new
  3. # configuration; then moves the updated configuration in place
  4. set -e
  5. SVN=$(which svn)
  6. TMPDIR=$(mktemp -d);
  7. HOSTNAME=$(hostname);
  8. if [ "$HOSTNAME" = "buxtehude" ]; then
  9. BASEDIR="/org/bugs.debian.org"
  10. USERCONF="bugs/user_prefs";
  11. elif [ "$HOSTNAME" = "bendel" ]; then
  12. BASEDIR="/var/list/.etc";
  13. USERCONF="lists/user_prefs";
  14. else
  15. echo "Unknown hostname '$HOSTNAME'";
  16. exit 1;
  17. fi;
  18. SACONFIG="$BASEDIR/spamassassin_config";
  19. BAKDIR="$BASEDIR/spamassassin_config_bak";
  20. # because alioth continuously fails, make sure that svn info will
  21. # succeed first before cluttering the log. Ideally we would report
  22. # this error, but it happens far too frequently, so we bail out here.
  23. if ! svn info $(svn info $SACONFIG|awk '/^URL:/{print $2}') >/dev/null 2>&1; then
  24. exit 0;
  25. fi;
  26. # figure out if there's an update to be made
  27. ORIGREV=$(svn info $SACONFIG |awk '/^Revision:/{print $2}')
  28. NEWREV=$(svn info $(svn info $SACONFIG|awk '/^URL:/{print $2}')|awk '/^Revision:/{print $2}')
  29. # no changes, bug out.
  30. if [ "0$ORIGREV" -ge "0$NEWREV" ]; then
  31. exit 0;
  32. fi;
  33. if [ -e "$SACONFIG/.update_spamassassin" ] && kill -0 $(cat "$SACONFIG/.update_spamassassin") >/dev/null 2>&1; then
  34. echo "Another update_spamassassin appears to be running"
  35. exit 1;
  36. else
  37. echo $$ > "$SACONFIG/.update_spamassassin";
  38. fi;
  39. remove_pidfile () {
  40. rm "$SACONFIG/.update_spamassassin";
  41. }
  42. trap remove_pidfile 0;
  43. FAILUREMESSAGE="";
  44. report_failure () {
  45. # Hrm; a previous update failed; don't report again until the file
  46. # is removed or it's more than a day old
  47. if [ -e "$SACONFIG/failed_update" ] &&
  48. [ $(($(date +%s) - $(stat -c '%Y' "$SACONFIG/failed_update"))) -lt 86400 ]; then
  49. rm -rf "$TMPDIR"
  50. exit 0;
  51. fi;
  52. echo "$FAILUREMESSAGE" > "$SACONFIG/failed_update"
  53. echo "$FAILUREMESSAGE";
  54. cat - <<EOF;
  55. update_spamassassin will only report this error once a day, and
  56. updates will not occur until this is fixed.
  57. Please fix the problem and then remove
  58. $SACONFIG/failed_update
  59. EOF
  60. rm -rf "$TMPDIR"
  61. exit 1;
  62. }
  63. cp -ar $SACONFIG $TMPDIR/.
  64. OLDDIR="$(pwd)"
  65. cd $TMPDIR/spamassassin_config;
  66. svn update -q --non-interactive;
  67. if svn status |grep -q '^C'; then
  68. FAILUREMESSAGE=$'The following conflicts were found\n\n'
  69. FAILUREMESSAGE="$FAILUREMESSAGE$(svn status|grep ^C)";
  70. report_failure
  71. fi;
  72. cd "$(pwd)"
  73. if ! spamassassin -p $TMPDIR/spamassassin_config/$USERCONF --lint > $TMPDIR/sa_lint 2>&1; then
  74. FAILUREMESSAGE="$(echo -e 'spamassassin -p $TMPDIR/spamassassin_config/$USERCONF --lint\nfailed with\n'| cat - $TMPDIR/sa_lint)";
  75. report_failure
  76. fi;
  77. mv "$SACONFIG" "$BAKDIR/spamassassin_config_r$ORIGREV"
  78. mv "$TMPDIR/spamassassin_config" "$SACONFIG"
  79. trap - 0
  80. remove_pidfile
  81. rm -rf "$TMPDIR"
  82. if [ "$HOSTNAME" = "buxtehude" ]; then
  83. touch /home/debbugs/.spamassassin/user_prefs
  84. elif [ "$HOSTNAME" = "bendel" ]; then
  85. # do nothing
  86. true;
  87. else
  88. echo "Unknown hostname '$HOSTNAME'";
  89. exit 1;
  90. fi;
  91. exit 0;