##  Clamav Signature Updater
##  Version 3.0; Copyrighted: 2006
##  Program Name: scamp.sh
##  Author: Gerard Seibert
##  Contact: gerard@seibercom.net
##  This program is free for individual use
##  You may modify this program in any way you so desire
##  The author assumes no responsibility for any changes made
##  to this program
##  Updates both scam.ndb.gz and phish.ndb.gz files
##  You will need to make sure that the paths are correct for your system
##
##  **********************************************************************
##  You will probably need to chmod this script to 0755
##  This script must be run as root.
##  You need 'wget' installed.
##  Make sure the path is correctly set
##  Using 'which wget' sans quotes, should show the path.
##  Check the path for 'chown'and 'chmod' also.
##  Alter the paths for them in the variables table at the
##  top of the program.
##  Make sure the 'clamav' setting is correct.
##  Report any problems to me at the address above!
##
##  Usually running from 'roots' CRONTAB
##  every four (4) hours will suffice.
##
##  Example (root's crontab)
##  
##  min hour mday month wday command
##  1   */4  *    *     *    /*path*/*to*/scamp.sh
##
##  Be sure to change the 'L_DIR' variable to accommodate your system.
##  This will write a log file detailing what 'wget' has fetched.
##  Example: L_DIR="/path/to/log/file" You need the quote marks.
##  DO NOT alter the N_DIR variable
##  Make sure the file is writeable.
##  If no file is specified, the script will issue a warning and exit.
##  I may change this behavior at some point in the future.
##
##  The shebang is set for 'bash' on a FreeBSD 6.1 STABLE system.
##  You may need to change it to accommodate your system.
##
##  If you find this program useful, discovered a bug,
##  or just need help, email me at the address at the top of this page.
##  ***********************************************************************
##  ***********************************************************************
##  ********************** Code Starts Here *******************************
##
##  Set up the variables here!
##

#!/bin/bash
L_DIR="/var/log/clam.log" # *****Be sure to set this*****
N_DIR=""                                        # Test to see if log exists
CH_OWN="/bin/chown"                        # Path to chown
CH_MOD="/bin/chmod"                             # Path to chmod
GUN_ZIP="/bin/gunzip"                 # Path to gunzip
W_GET="/usr/bin/wget"                     # Path to wget
C_DIR="/var/lib/clamav"                          # Path to clamav directory
DL_PATH="http://www.sanesecurity.com/clamav/"   # Path to download
FQN_P="phish"                                   # Base phishing name
FQN_S="scam"                                    # Base scam name
SUF=".ndb.gz"                                   # Suffix for downloaded files
#####

get_files ()
{
 if [ "$L_DIR" = "$N_DIR" ]; then
  echo "You must specify a log directory!"
  echo "Please complete the L_DIR variable at the top ot the script."
  exit 1
    else
      for i in $FQN_P $FQN_S
	do
	 $W_GET -a $L_DIR -P $C_DIR -N $DL_PATH/$i.ndb.gz
	 got_files $i
      done
  fi
}
##
got_files ()
{
  for j in $i
    do
      if  [ ! -e $C_DIR/$i.ndb.gz ]; then
	echo "File " $i " is missing"
	echo ""
	echo "You can safely ignore the other error messages"
	echo "Please try again later"
	return
	 else
	  install $i
      fi
  done
}
##
install ()
{
  for k in $i
    do
      if  ! [ -e $C_DIR/$i.old ]; then
        $GUN_ZIP -d -f <$C_DIR/$i.ndb.gz> $C_DIR/$i.ndb
	cp -fp $C_DIR/$i.ndb $C_DIR/$i.old
	change_owner $i.ndb $i.old $i.ndb.gz
	echo -n "Updated:  " $i.ndb " "&& date
	 elif [ $C_DIR/$i.ndb.gz -nt $C_DIR/$i.old ]; then
            $GUN_ZIP -d -f <$C_DIR/$i.ndb.gz> $C_DIR/$i.ndb
            cp -fp $C_DIR/$i.ndb $C_DIR/$i.old
            echo -n "Updated:  " $i.ndb " " && date
            change_owner $i.ndb $i.old $i.ndb.gz
              else
                echo -n "No Update for:  " $i.ndb " Available " && date
      fi
  done
}
##
change_owner ()
{
  cd $C_DIR
    for z in $1 $2 $3
      do
        $CH_OWN clamav:clamav $1
        shift
     done
}
##
get_files
##
##	We are so out of here!!

