#!/bin/bash

# JKF This is part of MailScanner.
# Call sa-update and sa-compile if you have them both.
# If you want to add arguments (such as channel file settings) to sa-update
# then do it by editing /etc/sysconfig/MailScanner, *NOT* by editing this
# script.

SAUPDATE=/usr/bin/sa-update
SACOMPILE=/usr/bin/sa-compile
SAUPDATEARGS=""
if [ -f /etc/sysconfig/MailScanner ] ; then
        . /etc/sysconfig/MailScanner
fi
export SAUPDATE
export SACOMPILE
export SAUPDATEARGS
LOGFILE=/tmp/update_spamassassin.$(date +%m%d)

# Update SpamAssassin rules
[ -x $SAUPDATE ] || exit 0
$SAUPDATE $SAUPDATEARGS >$LOGFILE 2>&1

# If we have sa-compile and they are using the Rule2XSBody plugin then compile
if test -x $SACOMPILE && grep -q '^loadplugin.*Rule2XSBody' /etc/mail/spamassassin/*pre 2>/dev/null ; then
  $SACOMPILE >>$LOGFILE 2>&1
fi

/etc/init.d/MailScanner reload >>$LOGFILE 2>&1

rm -f $LOGFILE

exit 0
