2006-12-14 20:36:20 +00:00
|
|
|
#!/bin/bash
|
2009-09-25 04:15:56 +00:00
|
|
|
# *** DO NOT MODIFY THIS FILE ***
|
2009-12-28 06:42:03 +00:00
|
|
|
#
|
2009-12-29 03:18:05 +00:00
|
|
|
# /etc/mail/spamassassin/channels/*.conf
|
|
|
|
# Place files here to add custom channels.
|
2009-12-28 06:42:03 +00:00
|
|
|
#
|
2009-12-29 03:18:05 +00:00
|
|
|
|
|
|
|
# list files in a directory consisting only of alphanumerics, hyphens and
|
|
|
|
# underscores
|
|
|
|
# $1 - directory to list
|
|
|
|
# $2 - optional suffix to limit which files are selected
|
|
|
|
run_parts_list() {
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
echo "ERROR: Usage: run_parts_list <dir>" > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! -d "$1" ]; then
|
|
|
|
echo "ERROR: Not a directory: $1" > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "$1" ]; then
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
find_opts='-name *'$2
|
|
|
|
fi
|
|
|
|
find -L $1 -mindepth 1 -maxdepth 1 -type f $find_opts | sort -n
|
|
|
|
fi
|
|
|
|
}
|
2006-12-14 20:36:20 +00:00
|
|
|
|
2009-12-28 06:42:03 +00:00
|
|
|
# Proceed with sa-update if spam daemon is running or forced in /etc/sysconfig/sa-update
|
|
|
|
unset SAUPDATE
|
|
|
|
[ -f /etc/sysconfig/sa-update ] && . /etc/sysconfig/sa-update
|
|
|
|
for daemon in spamd amavisd; do
|
|
|
|
/sbin/pidof $daemon >& /dev/null
|
|
|
|
[ $? -eq 0 ] && SAUPDATE=yes
|
|
|
|
done
|
|
|
|
|
|
|
|
# Skip sa-update if daemon not detected
|
|
|
|
[ -z "$SAUPDATE" ] && exit 0
|
|
|
|
|
2009-09-25 04:15:56 +00:00
|
|
|
# sa-update must create keyring
|
|
|
|
if [ ! -d /etc/mail/spamassassin/sa-update-keys ]; then
|
|
|
|
sa-update
|
|
|
|
fi
|
|
|
|
|
2009-12-29 03:18:05 +00:00
|
|
|
# Initialize Channels and Keys
|
|
|
|
CHANNELLIST=""
|
|
|
|
KEYLIST=""
|
|
|
|
# Process each channel defined in /etc/mail/spamassassin/channels/
|
|
|
|
for file in $(run_parts_list /etc/mail/spamassassin/channels/ .conf); do
|
|
|
|
# Validate config file
|
|
|
|
PREFIXES="CHANNELURL KEYID BEGIN"
|
|
|
|
for prefix in $PREFIXES; do
|
|
|
|
if ! grep -q "$prefix" $file; then
|
|
|
|
echo "ERROR: $file missing $prefix"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
. $file
|
|
|
|
echo "CHANNELURL=$CHANNELURL"
|
|
|
|
echo "KEYID=$KEYID"
|
|
|
|
CHANNELLIST="$CHANNELLIST $CHANNELURL"
|
|
|
|
KEYLIST="$KEYLIST $KEYID"
|
|
|
|
sa-update --import $file
|
|
|
|
done
|
|
|
|
|
|
|
|
# Sleep random amount of time before proceeding to avoid overwhelming the servers
|
|
|
|
sleep $(expr $RANDOM % 7200)
|
|
|
|
|
|
|
|
unset arglist
|
|
|
|
# Run sa-update on each channel, restart spam daemon if success
|
|
|
|
for channel in $CHANNELLIST; do
|
|
|
|
arglist="$arglist --channel $channel"
|
|
|
|
done
|
|
|
|
for keyid in $KEYLIST; do
|
|
|
|
arglist="$arglist --gpgkey $keyid"
|
|
|
|
done
|
|
|
|
/usr/bin/sa-update $arglist
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
/etc/init.d/spamassassin condrestart > /dev/null
|
|
|
|
[ -f /etc/init.d/amavisd ] && /etc/init.d/amavisd condrestart > /dev/null
|
|
|
|
fi
|