mcafee-autoupdate patch -- Tony Finch r-u-there?

Tony Finch dot at DOTAT.AT
Wed Jul 2 19:32:30 IST 2003


Mariano Absatz <mailscanner at LISTS.COM.AR> wrote:
>
>Tony, would you care to incorporate it (or suggest a modification, maybe
>another different command line option)?

I wasn't particularly keen on the feature since it can be implemented
with a trivial shell script -- you could even fit it in the crontab
itself. But anyway, I was bored this afternoon, so I did some polishing
of my script...

Tony.
--
f.a.n.finch  <dot at dotat.at>  http://dotat.at/
FAIR ISLE FAEROES: NORTHERLY 4 OR 5, OCCASIONALLY 6 IN EAST FAIR ISLE.
OCCASIONAL DRIZZLE. MODERATE OR GOOD.


#!/bin/sh -e
#
# Update the McAfee data files.
#
# $Cambridge: hermes/build/bin/uvscan-update,v 1.24 2003/07/02 18:25:47 fanf2 Exp $

# This is the directory where the uvscan binary is (NOT a symlink to
# the binary), which is where it looks for its dat files. You may run
# uvscan via a symlink to this place (e.g. from /usr/local/bin/uvscan)
# and it will still look for the dat files here. If uvscan's library
# dependencies can be found in a standard place (e.g. /usr/local/lib)
# then you don't need a wrapper script to set LD_LIBRARY_PATH before
# running it.
#
# The dat files are installed in a subdirectory named according to
# their version number, with symlinks from this directory into the
# subdirectory. The links are updated without locking on the
# assumption that this is sufficiently unlikely to cause a problem.
#
LIBDIR=/opt/uvscan

FTPDIR=ftp://ftp.csx.cam.ac.uk/pub/software/antivirus/datfiles/4.x
#FTPDIR=ftp://ftpeur.nai.com/pub/antivirus/datfiles/4.x

# ensure the path is plausible
PATH=$LIBDIR:/usr/local/bin:/usr/bin:/bin
export PATH

# handle the command line
OPTS="$*"
option () {
        case $OPTS in
        -*$1*)  eval $2=yes
        esac
}
case $OPTS in
[!-]*|*[!-frtv]*)
        echo "usage: $0 [-frtv]"
        echo "  -f      force update"
        echo "  -r      show README"
        echo "  -t      timestamp output"
        echo "  -v      verbose"
        exit 1
        ;;
esac
option f FORCE
option r README
option t TIME
option v VERBOSE
case $FORCE in
yes)    VERBOSE=yes
esac

# wrapper functions for echo etc.
timestamp () {
        case $TIME in
        yes)    date "+%Y-%m-%d %H:%M:%S "
        esac
}
say () {
        case $VERBOSE in
        yes)    echo "`timestamp`$*"
        esac
}
run () {
        say "> $*"
        "$@"
}
say Starting $0

# version number pattern
MATCH="[0-9][0-9][0-9][0-9]"

# work out latest dat version
cd $LIBDIR
CMD="wget --passive-ftp $FTPDIR/update.ini 2>update.err"
say "> $CMD"
if eval "$CMD"
then
        VERSION=`cat update.ini | sed "/^DATVersion=\($MATCH\).$/!d;s//\1/;q"`
else
        cat update.err
        VERSION=UNKNOWN
fi
run rm -f update.*

DATDIR=$LIBDIR/$VERSION
FILE=dat-$VERSION.tar

badversion () {
        VERBOSE=yes
        say "Failed to get McAfee datfile update from $FTPDIR"
        say "FTP version number \"$VERSION\" $*"
        run exit 1
}

# check the format of the version number
case $VERSION in
$MATCH) : ok
        ;;
*)      badversion does not match "$MATCH"
        ;;
esac

# already got it?
if [ -d $DATDIR ]
then
        case $FORCE in
        yes)    say Forced removal of $DATDIR
                run rm -rf $DATDIR
                ;;
        *)      say Already have "$VERSION"
                run exit 0
                ;;
        esac
fi

# work out installed dat version
run cd $LIBDIR
if ls -d $MATCH >/dev/null 2>&1
then
        INSTALLED=`ls -d $MATCH | tail -1`
else
        # no installed version so get whatever is available
        INSTALLED=0000
fi

# check new version is actually newer
if [ $VERSION -lt $INSTALLED ]
then
        badversion older than installed "$INSTALLED"
fi

VERBOSE=yes

say Installed dat file is "$INSTALLED"
say Latest dat file is "$VERSION"

# fetch and extract dat files
run mkdir $DATDIR
run cd $DATDIR
run wget --passive-ftp --progress=dot:mega $FTPDIR/$FILE
run tar xvf $FILE

# verify the contents
fail () {
        trap EXIT
        echo "$OUT"
        say Test run failed -- removing bad McAfee data files
        run rm -rf $DATDIR
        run exit 1
}
trap fail EXIT
CMD="uvscan --dat $DATDIR --version 2>&1"
say "> $CMD"
OUT=`$CMD`
case "$OUT" in
*"Missing or invalid DAT"* | \
*"Data file not found"* | \
*"Removal datafile clean.dat not found"* | \
*"Unable to remove viruses"* )
        fail
        ;;
esac
trap EXIT

echo "$OUT"
say Update OK

run cd $DATDIR
# show information on this update?
case $README in
yes)    run sed 's/[[:cntrl:]]//g
                1,/^NEW VIRUSES DETECTED/d
                /^UNDERSTANDING VIRUS NAMES/,$d
                s/^/# /' readme.txt
esac
# remove some crap
run rm -f *.diz *.exe *.ini *.lst *.tar *.txt
# change the current dat file links
for file in *.dat
do
        run rm -f ../$file
        run ln -s $VERSION/$file ..
done

say Completed OK
run exit 0

# done



More information about the MailScanner mailing list