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