/[pkg-listmaster]/trunk/spamassassin_config/update_spamassassin
ViewVC logotype

Contents of /trunk/spamassassin_config/update_spamassassin

Parent Directory Parent Directory | Revision Log Revision Log


Revision 316 - (hide annotations) (download)
Sat Sep 19 23:44:12 2009 UTC (3 years, 8 months ago) by don
File size: 2719 byte(s)
 * fix update spamassassin to cd back to the original directory, which
   hopefully will stop problems with removing the tempdir
1 don 75 #!/bin/sh
2    
3     # This command updates the spamassassin configuration; tests the new
4     # configuration; then moves the updated configuration in place
5    
6     set -e
7    
8     SVN=$(which svn)
9    
10     TMPDIR=$(mktemp -d);
11    
12 don 124 if [ "$HOSTNAME" = "rietz" ]; then
13 don 75 BASEDIR="/org/bugs.debian.org"
14     USERCONF="bugs/user_prefs";
15 don 124 elif [ "$HOSTNAME" = "liszt" ]; then
16 don 75 BASEDIR="/var/list/.etc";
17 don 97 USERCONF="lists/user_prefs";
18 don 75 else
19     echo "Unknown hostname '$HOSTNAME'";
20     exit 1;
21     fi;
22    
23     SACONFIG="$BASEDIR/spamassassin_config";
24     BAKDIR="$BASEDIR/spamassassin_config_bak";
25    
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    
30     # no changes, bug out.
31 don 137 if [ "0$ORIGREV" -ge "0$NEWREV" ]; then
32 don 75 exit 0;
33     fi;
34    
35 don 97 if [ -e "$SACONFIG/.update_spamassassin" ] && kill -0 $(cat "$SACONFIG/.update_spamassassin") >/dev/null 2>&1; then
36 don 75 echo "Another update_spamassassin appears to be running"
37     exit 1;
38     else
39     echo $$ > "$SACONFIG/.update_spamassassin";
40     fi;
41    
42     function remove_pidfile(){
43     rm "$SACONFIG/.update_spamassassin";
44     }
45    
46     trap remove_pidfile ERR;
47    
48     FAILUREMESSAGE="";
49     function report_failure(){
50     # Hrm; a previous update failed; don't report again until the file
51 don 293 # is removed or it's more than a day old
52     if [ -e "$SACONFIG/failed_update" ] &&
53     [ $(($(date +%s) - $(stat -c '%Y' "$SACONFIG/failed_update"))) -lt 86400 ]; then
54 don 151 rm -rf "$TMPDIR"
55 don 75 exit 0;
56     fi;
57 don 293 echo "$FAILUREMESSAGE" > "$SACONFIG/failed_update"
58 don 87 echo "$FAILUREMESSAGE";
59     cat - <<EOF;
60    
61 don 293 update_spamassassin will only report this error once a day, and
62     updates will not occur until this is fixed.
63 don 87
64     Please fix the problem and then remove
65     $SACONFIG/failed_update
66     EOF
67 don 151 rm -rf "$TMPDIR"
68 don 75 exit 1;
69     }
70    
71     cp -ar $SACONFIG $TMPDIR/.
72 don 316 OLDDIR="$(pwd)"
73 don 75 cd $TMPDIR/spamassassin_config;
74     svn update -q --non-interactive;
75     if svn status |grep -q '^C'; then
76 don 94 FAILUREMESSAGE=$'The following conflicts were found\n\n'
77 don 75 FAILUREMESSAGE="$FAILUREMESSAGE$(svn status|grep ^C)";
78     report_failure
79     fi;
80 don 316 cd "$(pwd)"
81 don 75
82 don 95 if ! spamassassin -p $TMPDIR/spamassassin_config/$USERCONF --lint > $TMPDIR/sa_lint 2>&1; then
83     FAILUREMESSAGE="$(echo -e 'spamassassin -p $TMPDIR/spamassassin_config/$USERCONF --lint\nfailed with\n'| cat - $TMPDIR/sa_lint)";
84 don 75 report_failure
85     fi;
86     mv "$SACONFIG" "$BAKDIR/spamassassin_config_r$ORIGREV"
87     mv "$TMPDIR/spamassassin_config" "$SACONFIG"
88 don 109 trap - ERR
89 don 93 remove_pidfile
90 don 75 rm -rf "$TMPDIR"
91    
92     if [ "$HOSTNAME" == "rietz" ]; then
93     touch /home/debbugs/.spamassassin/user_prefs
94 joey 118 elif [ "$HOSTNAME" == "liszt" ]; then
95 don 75 # do nothing
96 don 96 true;
97 don 75 else
98     echo "Unknown hostname '$HOSTNAME'";
99     exit 1;
100     fi;
101    
102    
103 don 93 exit 0;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5