Author Topic: avast-update: a more verbose script  (Read 8185 times)

0 Members and 1 Guest are viewing this topic.

hlingler

  • Guest
avast-update: a more verbose script
« on: July 25, 2007, 08:52:14 AM »
Hello:

The avast-update script provided with avast4workstation is very quiet when run from the CLI.  I would like it to be just a little more verbose.  I have never before tried to write/edit a shell script.  But I read all of the documentation on avast (man avast), and some documentation on shell scripts, and came up with this:
Code: [Select]
#!/bin/sh
#
    avastupdateloc=`type avast-update|cut -f3 -d' '`
    echo "Executing $avastupdateloc..." >&2
    avastver=`rpm -qf $avastupdateloc`
    echo "$avastver updater." >&2

AVASTDIR=$HOME/.avast
VPSFILE=$AVASTDIR/400.vps
URL_UPDATE="http://files.avast.com/files/latest/400.vps"
URL_UPDATE_MD5="http://files.avast.com/files/latest/400vps.md5"

if test ! -d $AVASTDIR ; then
    echo "You have to run avast! at least once before you can update it." >&2
    exit 1
fi

if test -f $AVASTDIR/lockfile-$USER ; then
    echo "avast! is running, can't update." >&2
    exit 1
fi

if test -f $VPSFILE ; then
    md5_current=`md5sum $VPSFILE | cut -c1-32`
fi

    echo "Checking for virus signature updates..." >&2
file_md5=$VPSFILE.new.md5
wget -q -O $file_md5 $URL_UPDATE_MD5 && md5_update=`cat $file_md5 | cut -c1-32`
rm -f $file_md5

if test "x$md5_current" != "x$md5_update" ; then
    echo "An update for $VPSFILE is available.  Fetching update..." >&2
    wget -q  -O $VPSFILE.new.$$ $URL_UPDATE && mv -f $VPSFILE.new.$$ $VPSFILE
    vpsver=`ls -l $VPSFILE|cut -f6-8 -d' '`
    echo "Update done: $VPSFILE dated $vpsver." >&2
else
    echo "No updates available at this time." >&2
fi
The changes that I made are all minor: just added a couple "echo" lines and the "else" case.  This script seems to run OK from the CLI.  I would like to hear feedback on this revised script from anyone knowledgeable: Does it look OK?  Are there any potential problems, especially if/when it is "called" from the GUI?

Any feedback will be appreciated.  If this script does look OK, feel free to use it! ;D

EDIT: Made a couple more minor changes: echo start of avast-update and list VPS file date/time after an update.

EDIT#2: Made a couple more minor changes: resolve and echo avast-update location and Avast! version name, and improve/expand echo of VPSFILE name/location and date.  This script works for me, and I will not make any more changes.  Also, I forgot to mention that this script should trigger an internal system e-mail, containing the echo outputs and directed to the username, when run as a cron job.  I would still like to read any feedback, particularly from anyone who has better knowledge of shell scripts, and can point out any potential problems.  Thanx and enjoy!

Thanx,
Vince

Avast Free Linux Home Edition (avast4workstation-1.0.8-1.i586.rpm)
uname -a: Linux 2.6.20-1.2952.fc6 #1 SMP Wed May 16 18:59:18 EDT 2007 i686 athlon i386 GNU/Linux
Compaq Presario SR2020NX, AMD Athlon 64 3500+ (~2.2GHz, stepped), nvidia GeForce 6150 LE graphics, 512MB RAM, sda SATA 160 GB, sdb SATA 250GB
Dual Boot: Fedora Core 6 and Windows XP MCE
« Last Edit: July 30, 2007, 06:44:00 PM by hlingler »