#!/bin/sh # Script freely provided by Bill Landry (bill@inetmsg.com). # # Version 1.5 (updated 8/17/07 - Thanks to Dan Larsson for his contrabutions) # - Added separate variable for ClamAV group ID for setting # appropriate file group access permissions. # - Added variables for signature file update URLs. # - Added support for automatic reloading of signature # databases when updates are found. # # Version 1.4 (updated 7/13/07) # - Added checks to verify that the signature files exist, # and if not, do an initial download, decompress and test. # - Added variables for clamav signatures location path and # clamd user account (the account that clamd runs under). # - Added/modified script comments. # # Version 1.3 # - Added checks to either confirm the existance of the # temporary working directories or to create them. # - Changed "cp --reply=yes" to "cp -f". If this # causes problems with older versions of "cp", # you will need to change it back. # # Version 1.2 # - Repointed URLs for SaneSecurity downloads to # the new mirror redirect links. # # Version 1.1 # - Converted MSRBL downloads from curl to rsync. # # Version 1.0 (initial script created). #################################################################### # SCRIPT USER EDIT SECTION - SET PROGRAM PATHS AND OTHER VARIABLES # #################################################################### # Edit quoted variables below to meet your own particular # needs/requirements, but do not remove the "quote" marks. # Set and export program paths. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin export PATH # Set path to clamd.pid file (see clamd.conf for path location). # To disable automatic signature database reloading, comment out # the next line. clamd_pid=/var/run/clamd/clamd.pid # Set path to ClamAV signature files location . clam_sigs="/var/lib/clamav" # Set ClamD user and group accounts. clam_user="clamav" clam_group="clamav" # Set temp working directory paths (edit to meet your own needs). tmp_dir="/var/tmp/clamdb" rsync_dir="/var/tmp/rsync" # SaneSecurity source URLs - *MUST* be HTTP URLs, one URL per line. # Add/remove/modify URLs between quote makes as needed. To disable # SaneSecurity downloads, comment out the next four lines. ss_urls=" http://www.sanesecurity.com/clamav/phishsigs/phish.ndb.gz http://www.sanesecurity.com/clamav/scamsigs/scam.ndb.gz " # MSRBL source URLs - *MUST* be RSYNC URLs, one URL per line. # Add/remove/modify URLs between quote marks as needed. To # disable MSRBL downloads, comment out the next four lines. msrbl_urls=" rsync://rsync.mirror.msrbl.com/msrbl/MSRBL-Images.hdb rsync://rsync.mirror.msrbl.com/msrbl/MSRBL-SPAM.ndb " ################################################################################ # END OF SCRIPT USER EDIT SECTION - YOU SHOULD NOT NEED TO EDIT ANYTHING BELOW # ################################################################################ # Check to see if the working directories shown above were created. # If not, create them. Otherwise, ignore and proceed with script. mkdir -p $tmp_dir $rsync_dir # Change shell to the ClamAV signature files directory. cd $clam_sigs # Check for existing SaneSecurity signature files. If they exist, then run # the update checks. Otherwise, just download, extract and test the files. for source_url in $ss_urls ; do source_file=`basename $source_url` target_file=`basename $source_url .gz` echo echo ============================================ echo SaneSecurity $target_file Signature File Update echo ============================================ echo if [ ! -s $target_file ] then curl -L -R -o $tmp_dir/$source_file $source_url test -s $tmp_dir/$source_file && \ gunzip -cdf $tmp_dir/$source_file > $tmp_dir/$target_file && \ clamscan --quiet -d $tmp_dir/$target_file - < /dev/null && \ mv -f $tmp_dir/$target_file $tmp_dir/$source_file . && \ do_clamd_reload=1 else curl -L -R -z $source_file -o $tmp_dir/$source_file $source_url test -s $tmp_dir/$source_file && \ gunzip -cdf $tmp_dir/$source_file > $tmp_dir/$target_file && \ clamscan --quiet -d $tmp_dir/$target_file - < /dev/null && \ cp -f $target_file $target_file-bak && \ mv -f $tmp_dir/$target_file $tmp_dir/$source_file . && \ do_clamd_reload=1 fi done # Check for existing MSRBL signature files. If they exist, then run the # update checks. Otherwise, just download, extract and test the files. for source_url in $msrbl_urls ; do target_file=`basename $source_url` echo echo ============================================ echo MSRBL $target_file Signature File Update echo ============================================ if [ ! -s $target_file ] then rsync -t --stats $source_url $rsync_dir/$target_file cp -p $rsync_dir/$target_file $tmp_dir && \ test -s $tmp_dir/$target_file && \ clamscan --quiet -d $tmp_dir/$target_file - < /dev/null && \ mv -f $tmp_dir/$target_file . && \ do_clamd_reload=1 else rsync -tu --stats $source_url $rsync_dir/$target_file test $rsync_dir/$target_file -nt $target_file && \ cp -p $rsync_dir/$target_file $tmp_dir && \ test -s $tmp_dir/$target_file && \ clamscan --quiet -d $tmp_dir/$target_file - < /dev/null && \ cp -f $target_file $target_file-bak && \ mv -f $tmp_dir/$target_file . && \ do_clamd_reload=1 fi done # Set appropriate file access permissions chown -R $clam_user:$clam_group $clam_sigs # Remove any leftover files in the $tmp_dir working directory (this # should only happen if a corrupted signature file is detected) rm -f $tmp_dir/* # Reload all clamd signature databases if updates detected and # neither $clamd_pid nor $do_clamd_reload are null. if [ -n "$clamd_pid" -a -n "$do_clamd_reload" ] ; then echo echo ============================== echo Reloading the ClamAV databases echo ============================== kill -USR2 `cat $clamd_pid` fi exit $?