View Single Post
  #12  
Old 1st January 2008, 02:40
davy davy is offline
Member
 
Join Date: Aug 2007
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by rbartz
In the Developers Forum, there is a script written by George Vieira and modified by djtremors for ISPC that would update CLAMAV definitions automatically (when run regularly by a cron job) and even upgrade the clamav program if there is a new one.

http://www.howtoforge.com/forums/showthread.php?t=7937

I wanted to update my clamav installation to the newest one today, so I tried the script. I had to make a few minor changes for my OS, but it worked fine and upgraded my clamav installation in ispconfig from 0.88.7 to 0.90.

Here is the original script:

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

# place your ISPC admin email address here.
ADMIN="admin@wvis1.net"

# 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`"
        [ "$?" != 0 ] && ( echo "Error with finding new version off clamav.net site. URL may have changed!";exit 1;)

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

}

if [ ! -f /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 [ -d "clamav-$OLD" ]; then
                rm -fr "clamav-$OLD"
        fi

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

        if [ $RESULT = 0 ]; 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>&1 || 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 -f /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
In order for this to work on my Fedora Core 4 server, I had to change the sendmail on lines 18 and 20 to "/usr/sbin/sendmail" and to change "webget" on line 56 to "wget". I also had to create a "clamav" user and "clamav" group.

All you do from there is to save the file on your server (I named it "getfreshclam"), chmod it 0755, and run it while you are root.

It checked my old version, checked for newest one, went and got the new install tar and installed it. THANKS GEORGE and DJTREMORS.... I no longer need to wait for an ispconfig update to freshen my clamav installation!

NOTE that on my Fedora Core 3 server, I did not get the same value for $VERSION. I had to change "|cut -d ' ' -f 4" to "|cut -d ' ' -f 3" to get the version number. Even then, the line [ "$NEWUPDATE" ] && NEW="`findversion`" failed to reassign $NEW so the script fails on FC3. In other words, the script may not work on your OS... you may need to adjust a few things! Use it at your own risk!

Cheers,

RDB
I am using CentOS 5.1(86_64).i got an error when i run this script.

[root@server1 ~]# ./clamav_update
./clamav_update: line 62: cd: clamav-0.92: No such file or directory
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target `install'. Stop.
cp: cannot stat `COPYING': No such file or directory
cp: cannot stat `clamav.conf': No such file or directory
cp: cannot stat `freshclam.conf': No such file or directory
Shutting down ISPConfig system...
/root/ispconfig/httpd/bin/apachectl stop: httpd stopped
ISPConfig system stopped!
Starting ISPConfig system...
/root/ispconfig/httpd/bin/apachectl startssl: httpd started
ISPConfig system is now up and running!

How can i fix it?

Thanks alot.
Reply With Quote