#!/bin/sh # Auto update script for subdomains / subdirectory spams # See http://nospam.mailpeers.net # # Ver 1.00 dec 14, 2005 # # Used for fast changing rules. should be executed every few hours # Please do not run more than once an hour, and use a random number # of minutes for the exact time to prevent download peaks # # The only parameter is -v for verbose mode # # processor intensive commands are executed at the lowest priority level # There is an option to exit if the processor load is too high ##### CONFIGURATION ##### # Spamassassin rules directory # ( Debian : /etc/spamassassin/ ) # ( FreeBSD : /usr/local/etc/mail/spamassassin/ ) rulesdir='/etc/mail/spamassassin/' # temporary directory tmpdir='/tmp/' # The name of the ruleset (choose between the full or limited version) rulesname='subevil' # rulesname='subevil200' # Where should alerts be sent in case of warnings/errors # Please replace with your own email address # blank= no alerts (not recommanded) alertemail="yourfirstmail@yourdomain.co_m yoursecondmail@anotherdomain.co_m" # Rules location rulesurl='http://nospam.mailpeers.net/' # Keep going if those warnings are encountered (egrep syntax) okwarnings='^warning:.*(description|score set).*(is over.*chars| for non-existent rule)' # Test spamassassin integrity before changing the rules (safer) pretest=1 # Test spamassassin integrity after changing the rules (should not be disabled) postest=1 # Max processor load: if the processor load is above this value, the update will be skipped # Value is 100x the actual load # To disable this function, set the value to 0 maxload=250 # ----------- DO NOT EDIT BELOW THIS LINE (unless you know what you're doing) --------------- vecho (){ if [ "$verbose" = "-v" ] then echo "$1" fi } result='' verbose="$1" # Exit if the server is too loaded if [ "$maxload" -ge 0 ] then mn1=`uptime | cut -d":" -f5 | sed 's/ 0.0//g' | sed 's/ 0.//g' | tr --delete " " | tr --delete "." | cut -d"," -f1` vecho 'server load (x100) is '"$mn1" if [ "$mn1" -ge "$maxload" ] then vecho 'server load is too high (max:'"$maxload"') - exiting' exit fi fi # uncomment if you need to leave the temp dir clean, # else the rules file will simply stay there # #if test -f "$rulesdir$rulesname"'.cf' # then # cp -fpu $rulesdir$rulesname'.cf' $tmpdir$rulesname'.cf' # fi # Download the rules only if newer cd $tmpdir if [ "$verbose" = "-v" ] then nice -n19 wget -N "$rulesurl$rulesname"'.cf' else nice -n19 wget -N "$rulesurl$rulesname"'.cf' -o /dev/null 2>&1; >/dev/null fi result=`diff "$tmpdir$rulesname"'.cf' $rulesdir$rulesname'.cf' 2>&1` if [ "$result" = '' ] then # uncomment if you need to leave the temp dir clean, # else the file will stay there # # rm -f "$tmpdir$rulesname"'.cf' vecho 'Rules already up to date - Exiting' exit fi vecho 'New rules downloaded' # Test if spamassassin is ok before proceeding if [ "$pretest" -ge 0 ] then vecho 'Test if spamassassin is ok before proceeding' result=`nice -n19 spamassassin --lint 2>&1 3>&1 | egrep -v '^lint:' | egrep -iv "$okwarnings"` if [ "$result" != '' ] then if [ "$alertemail" != '' ] then echo 'An error was detected in spamAssassin configuration. rules not updated '"$result" | mail -s 'Spamassassin alert.' $alertemail fi vecho 'An error was detected in spamAssassin configuration. rules not updated '"$result"' - exiting' # uncomment if you need to leave the temp dir clean, # else the file will stay there # # rm -f "$tmpdir$rulesname"'.cf' exit fi fi if test -f "$rulesdir$rulesname"'.cf' then cp -fpu $rulesdir$rulesname'.cf' $rulesdir$rulesname'.bak' fi cp -fpu $tmpdir$rulesname'.cf' $rulesdir$rulesname'.cf' # Test if spamassassin is ok after the update if [ "$postest" -ge 0 ] then vecho 'Test if spamassassin is ok after the update' result=`nice -n19 spamassassin --lint 2>&1 3>&1 | egrep -v '^lint:' | egrep -iv "$okwarnings"` if [ "$result" = '' ] then vecho 'Everything ok, reloading spamassassin.' if [ "$verbose" = "-v" ] then service spamassassin restart else service spamassassin restart > /dev/null fi sleep 8 result=`ps ax 2>/dev/null | grep -v grep | grep -c spamd` if [ $result -gt 0 ] then vecho 'Spamassassin reloaded successfully ('"$result"' process running)' else if [ "$alertemail" != '' ] then echo '[ERROR] Spamassassin could not be reloaded.' | mail -s '[ERROR] Spamassassin not reloaded.' $alertemail fi vecho '[ERROR] Spamassassin could not be reloaded' fi else rm -f $rulesdir$rulesname'.cf' if test -f "$rulesdir$rulesname"'.bak' then cp -fpu $rulesdir$rulesname'.bak' $rulesdir$rulesname'.cf' fi if [ "$alertemail" != '' ] then echo 'An error was detected in spamAssassin configuration. rules reverted '"$result" | mail -s 'Spamassassin alert.' $alertemail fi vecho 'An error was detected in spamAssassin configuration. rules not reverted '"$result"' - exiting' fi fi # uncomment if you need to leave the temp dir clean, # else the file will stay there # # rm -f "$tmpdir$rulesname"'.cf'