1 | #!/bin/sh |
---|
2 | # |
---|
3 | # $HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/gen/mailhub.sh $ $Id: mailhub.sh 3956 2010-01-05 20:56:56Z zacheiss $ |
---|
4 | |
---|
5 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/athena/bin:/usr/local/bin |
---|
6 | export PATH |
---|
7 | |
---|
8 | if [ -d /var/athena ] && [ -w /var/athena ]; then |
---|
9 | exec >/var/athena/moira_update.log 2>&1 |
---|
10 | else |
---|
11 | exec >/tmp/moira_update.log 2>&1 |
---|
12 | fi |
---|
13 | |
---|
14 | # The following exit codes are defined and MUST BE CONSISTENT with |
---|
15 | # error codes the library uses: |
---|
16 | MR_MKCRED=47836474 |
---|
17 | MR_MISSINGFILE=47836473 |
---|
18 | MR_NOCRED=47836470 |
---|
19 | |
---|
20 | root=/usr/local/sendmail |
---|
21 | |
---|
22 | if [ -r $root/etc/aliases.new ]; then |
---|
23 | chmod 644 $root/etc/aliases.new |
---|
24 | else |
---|
25 | exit $MR_MISSINGFILE |
---|
26 | fi |
---|
27 | |
---|
28 | if [ ! -r $root/etc/aliases ]; then |
---|
29 | logger -p mail.error -t mailhub.sh "No current aliases file, aborting." |
---|
30 | exit $MR_NOCRED |
---|
31 | fi |
---|
32 | |
---|
33 | # Play it safe and be sure we have reasonable data |
---|
34 | olines=`wc -l $root/etc/aliases | awk '{print $1}'` |
---|
35 | nlines=`wc -l $root/etc/aliases.new | awk '{print $1}'` |
---|
36 | diff=`expr $nlines - $olines` |
---|
37 | thresh=`expr $olines / 10` |
---|
38 | |
---|
39 | # Catch the zero case |
---|
40 | if [ $nlines -eq 0 ]; then |
---|
41 | logger -p mail.error -t mailhub.sh "Recieved empty aliases file, aborting." |
---|
42 | exit $MR_MISSINGFILE |
---|
43 | fi |
---|
44 | |
---|
45 | # If its a greater than 10% shift bomb out to be safe |
---|
46 | if [ $diff -gt $thresh ]; then |
---|
47 | logger -p mail.error -t mailhub.sh "Alias changes threshold exceeded, aborting." |
---|
48 | exit $MR_NOCRED |
---|
49 | fi |
---|
50 | |
---|
51 | cp /dev/null $root/etc/aliases.new.db |
---|
52 | |
---|
53 | $root/sbin/sendmail -bi -oA$root/etc/aliases.new |
---|
54 | if [ $? != 0 ]; then |
---|
55 | exit $MR_MKCRED |
---|
56 | fi |
---|
57 | |
---|
58 | sh /etc/init.d/sendmail stop |
---|
59 | |
---|
60 | mv $root/etc/aliases $root/etc/aliases.old |
---|
61 | mv $root/etc/aliases.db $root/etc/aliases.old.db |
---|
62 | mv $root/etc/aliases.new $root/etc/aliases |
---|
63 | mv $root/etc/aliases.new.db $root/etc/aliases.db |
---|
64 | |
---|
65 | sh /etc/init.d/sendmail start |
---|
66 | |
---|
67 | # Make sure the sendmail daemons are indeed running |
---|
68 | ps -ef | grep sendmail | grep -v grep > /dev/null 2>&1 |
---|
69 | if [ $? -ne 0 ]; then |
---|
70 | logger -p mail.error -t mailhub.sh "Sendmail failed to restart." |
---|
71 | exit $MR_MKCRED |
---|
72 | fi |
---|
73 | |
---|
74 | rm -f $0 |
---|
75 | exit 0 |
---|