HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Developers' Forum (http://www.howtoforge.com/forums/forumdisplay.php?f=18)
-   -   freshclam updated script (http://www.howtoforge.com/forums/showthread.php?t=7937)

djtremors 4th November 2006 22:59

freshclam updated script
 
hey all,

in a previous post somewhere I had a script mentioned which not only auto updates clamav but also checks if there's a new version and downloads/compiles and restarts whatever services.

I have now done it for ISPC if you guys want to try it out. You have to use the crontab option instead of the daemon to do updates as the script does it and also checks for binary updates.

I've done this to mine and so far it appears to work fine. The only time it ever broke was when the mirror no longer hosted it and i got an email notice about it to change the mirror setting.

Parameters needed to set are the ADMIN and the MIRROR variables, the rest are fine.

This beats waiting for a new ISPC to get an update or if your happy to keep your ispc version at least you get binary updates too.
PHP Code:

#!/bin/bash
# Version 1.01 by George Vieira

# place your ISPC admin email address here.
ADMIN="admin@yourdomain.com"

# place your preferred mirror server here.
MIRROR="http://optusnet.dl.sourceforge.net/sourceforge/clamav"

# -- Nothing to change under this line -----------------------------
LOG="/var/log/clamav-prog-update.log"
APPLICATION_NAME=ispconfig
COMPILE_DIR
=`pwd`

error()
{
        if [ 
"$ADMIN" ]; then
                
echo "Subject:CLAMUPDATE: $1" sendmail "$ADMIN"
        
else
                echo 
"Subject:CLAMUPDATE: $1" sendmail root
        fi
}

findversion()
{
        
VERSION="`host -t txt current.cvd.clamav.net | sed -e 's/"//g' |cut -d ' ' -f 4|cut -d : -f 1`"
        
"$?" != ] && ( echo "Error with finding new version off clamav.net site. URL may have changed!";exit 1;)

        echo 
"DETECTED VERSION -> $VERSION" >>$LOG 2>&1

}

if [ ! -
/var/log/clam-update.log ]; then
        touch 
/var/log/clam-update.log
        chown admispconfig 
/var/log/clam-update.log
        chmod 660 
/var/log/clam-update.log
fi

STATUS
="`/home/admispconfig/ispconfig/tools/clamav/bin/freshclam --log=/var/log/clam-update.log 2>&1`"

NEW="`echo \"$STATUS\" | grep \"WARNING: Local version\" | awk {'print $7'}`"
OLD="`echo \"$STATUS\" | grep \"WARNING: Local version\" | awk {'print $4'}`";
NEWUPDATE="`echo \"$STATUS\" |grep \"Current functionality level\"`"

"$NEWUPDATE" ] && NEW="`findversion`"

# If there's a NEW one, updated it.
if [ "$NEW" ]; then
        mkdir 
/root/ispc.updates 2>/dev/null
        cd 
/root/ispc.updates

        
if [ -"clamav-$OLD" ]; then
                rm 
-fr "clamav-$OLD"
        
fi

        webget 
-c $MIRROR/clamav-$NEW.tar.gz >>$LOG 2>&1
        RESULT
=$?

        if [ 
$RESULT ]; then
                tar xvfz clamav
-$NEW.tar.gz >/dev/null 2>&1
                cd 
"clamav-$NEW"

                
./configure --prefix=/home/adm${APPLICATION_NAME}/${APPLICATION_NAME}/tools/clamav 
                        
--sysconfdir=/home/adm${APPLICATION_NAME}/${APPLICATION_NAME}/tools/clamav/etc 
                        
--with-user=adm${APPLICATION_NAME} --with-group=adm${APPLICATION_NAME
                        --
disable-clamav --disable-bzip2 >>$LOG 2>&|| error "Could not configure ClamAV"
                
make || error "Could not make ClamAV"
                
make install || error "Could not install ClamAV"
                
cp -f COPYING /home/adm${APPLICATION_NAME}/${APPLICATION_NAME}/tools/clamav/
                
cd ${COMPILE_DIR}
                
cp -f clamav.conf /home/adm${APPLICATION_NAME}/${APPLICATION_NAME}/tools/clamav/etc/clamav.conf
                cp 
-f freshclam.conf /home/adm${APPLICATION_NAME}/${APPLICATION_NAME}/tools/clamav/etc/freshclam.conf
                rm 
-/home/adm${APPLICATION_NAME}/${APPLICATION_NAME}/tools/clamav/etc/clamd.conf
                cd 
/home/adm${APPLICATION_NAME}/${APPLICATION_NAME}/tools/clamav/etc/
                
ln -s clamav.conf clamd.conf
                cd 
${COMPILE_DIR}

                
# Bit of a shame we have to restart ALL the ISPC services and not only freshclam
                
/etc/rc.d/init.d/ispconfig_server restart

                error 
"Updated from OLD=$OLD -> NEW=$NEW"
        
else
                
error "Cannot fetch new CLAMAV version, check mirror address"
        
fi
fi 


till 5th November 2006 12:30

Looks nice. I will test it on my installation.

djtremors 11th December 2006 09:55

Update 1.01
 
Updated the script to handle "functional level" version messages and fetches the latest version from ClamAVs DNS.

don't forget to change the email and mirror to suite.


All times are GMT +2. The time now is 20:18.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.