#!/bin/sh
#
# mksupdate - mks_vir for Linux/FreeBSD virus database update by
# Tomasz Antosik <tomek@linux.com.pl>
#
# You may put it in cron file, for example like this:
#
# # updating mks_vir virus databases - every day at 6 a. m.
# 0 6 * * * 	/usr/local/sbin/mksupdate >>/dev/null 2>&1
#

# directory where databases are located (should be specified in /etc/mks.cfg)
mksdir=/var/mksvir
# name of a user and a group that runs the scanner (may not be important to you)
scanuser=amavis
scangroup=amavis
# who should be notified about changes?
mailto="root@localhost"

# external programs
chown=/bin/chown
chmod=/bin/chmod
grep=/bin/grep
mail=/usr/bin/mail
wget=/usr/bin/wget
test=/usr/bin/test
tar=/bin/tar
rm=/bin/rm
mv=/bin/mv

# OK, let's go ...

cd ${mksdir}
output=`${wget} -N -nd http://mksupdate.mks.com.pl/mkslinux/bazy.tgz 2>&1 | ${grep} "100%"`
if ${test} -n "${output}"; then
    ${tar} zxf bazy.tgz
    ${chown} ${scanuser}.${scangroup} *
    ${chmod} 440 *
    # send a mail to admin
    echo "${mksdir}: New data files present" | ${mail} -s "[mks_vir] Virus Database Update Completed" ${mailto}
else
    exit 0 # no new version :(
fi

