0dd949e
#!/bin/bash
c40bdd3
# *** DO NOT MODIFY THIS FILE ***
1fbc04e
#
5b2c534
# /etc/mail/spamassassin/channel.d/*.conf
b0a6ba1
#     Place files here to add custom channels.
1fbc04e
#
b0a6ba1
1fbc04e
# Proceed with sa-update if spam daemon is running or forced in /etc/sysconfig/sa-update
8b502a9
unset SAUPDATE OPTIONS DEBUG NOTIFY_UPD
1fbc04e
[ -f /etc/sysconfig/sa-update ] && . /etc/sysconfig/sa-update
8b502a9
[ "$SAUPDATE" = "no" ] && exit 0
a734837
for daemon in mimedefang spamd amavisd spampd; do
e3cf226
    /usr/bin/pgrep -f $daemon >& /dev/null
1fbc04e
    [ $? -eq 0 ] && SAUPDATE=yes
1fbc04e
done
1fbc04e
1fbc04e
# Skip sa-update if daemon not detected
1fbc04e
[ -z "$SAUPDATE" ] && exit 0
1fbc04e
c40bdd3
# sa-update must create keyring
c40bdd3
if [ ! -d /etc/mail/spamassassin/sa-update-keys ]; then
c40bdd3
    sa-update
c40bdd3
fi
c40bdd3
b0a6ba1
# Initialize Channels and Keys
b0a6ba1
CHANNELLIST=""
b0a6ba1
KEYLIST=""
5b2c534
# Process each channel defined in /etc/mail/spamassassin/channel.d/
5baef96
for file in /etc/mail/spamassassin/channel.d/*.conf; do
5baef96
    [ ! -f "$file" ] && continue
b0a6ba1
    # Validate config file
b0a6ba1
    PREFIXES="CHANNELURL KEYID BEGIN"
b0a6ba1
    for prefix in $PREFIXES; do
b0a6ba1
        if ! grep -q "$prefix" $file; then
b0a6ba1
            echo "ERROR: $file missing $prefix"
b0a6ba1
            exit 255
b0a6ba1
        fi
b0a6ba1
    done
5baef96
    . "$file"
e49978a
    #echo "CHANNELURL=$CHANNELURL"
e49978a
    #echo "KEYID=$KEYID"
b0a6ba1
    CHANNELLIST="$CHANNELLIST $CHANNELURL"
b0a6ba1
    KEYLIST="$KEYLIST $KEYID"
5baef96
    sa-update --import "$file"
b0a6ba1
done
b0a6ba1
b0a6ba1
# Sleep random amount of time before proceeding to avoid overwhelming the servers
b0a6ba1
sleep $(expr $RANDOM % 7200)
b0a6ba1
b0a6ba1
unset arglist
b0a6ba1
# Run sa-update on each channel, restart spam daemon if success
b0a6ba1
for channel in $CHANNELLIST; do
b0a6ba1
    arglist="$arglist --channel $channel"
b0a6ba1
done
b0a6ba1
for keyid in $KEYLIST; do
b0a6ba1
    arglist="$arglist --gpgkey $keyid"
b0a6ba1
done
8b502a9
/usr/bin/sa-update $OPTIONS $arglist
8b502a9
status=$?
8b502a9
now=`date +"%d-%b-%Y %T"`
8b502a9
# cron runs this script tee /var/log/sa-update.log
8b502a9
# We want to always write to the log, but only send mail
8b502a9
# as configured.  
8b502a9
if [ $status -eq 0 ]; then
8b502a9
        if [ -n "$DEBUG" -o -n "$NOTIFY_UPD" ]; then
8b502a9
	    echo "$now: SpamAssassin: Update processed successfully" 
8b502a9
	else
8b502a9
            echo "$now: SpamAssassin: Update processed successfully" >>/var/log/sa-update.log
8b502a9
	fi
a734837
	if [ -f /usr/bin/systemctl ]; then
a734837
		systemctl condrestart spamassassin.service >& /dev/null
a734837
		[ -f /usr/lib/systemd/system/amavisd.service ] && systemctl condrestart amavisd.service >& /dev/null
a734837
		systemctl --quiet is-active mimedefang.service; [ $? -eq 0 ] && systemctl reload mimedefang.service >& /dev/null
a734837
		[ -f /usr/lib/systemd/system/spampd.service ] && systemctl condrestart spampd.service >& /dev/null
a734837
	else
a734837
		service spamassassin condrestart >& /dev/null
a734837
		[ -f /etc/rc.d/init.d/amavisd ] && service amavisd-new condrestart >& /dev/null
a734837
		[ -f /etc/rc.d/init.d/mimedefang ]  && service mimedefang condrestart >& /dev/null
a734837
		[ -f /etc/rc.d/init.d/spampd ] && service spampd condrestart >& /dev/null
a734837
	fi
a734837
	
8b502a9
        exit $status
b0a6ba1
fi
8b502a9
if [ $status -eq 1 ]; then
8b502a9
        if [ -n "$DEBUG" ]; then
8b502a9
	    echo "$now: SpamAssassin: No update available"
8b502a9
	else
8b502a9
            echo "$now: SpamAssassin: No update available" >>/var/log/sa-update.log
8b502a9
	fi
8b502a9
        exit $status
8b502a9
fi
8b502a9
if [ $status -eq 2 ]; then
8b502a9
        echo "$now: SpamAssassin: Problem applying update - pre files failed lint check"
8b502a9
        exit $status
8b502a9
fi
8b502a9
if [ $status -eq 4 ]; then
8b502a9
        echo "$now: SpamAssassin: Update available, but download or extract failed"
8b502a9
        exit $status
8b502a9
fi
8b502a9
8b502a9
echo "$now: SpamAssassin: Unknown error code $status from sa-update"
8b502a9
exit $status