#!/bin/bash

# FetchAvUpdate by Ben Tasker
# Released under the GNU GPL v2 copyright to Ben Tasker 2008


# A script to manually download the ZoneAlarm Anti-Virus Signatures for use on standalone machines
# If the script won't seem to run, check that it is executable, run chmod +x FetchAvUpdate
# If it is running but kicking out errors check that you have;

# An internet connection on the system you are running this on
# wget
# grep
# sed

# If it is still giving you problems then email me at btasker@gmail.com with the subject line FetchAvUpdate
# make sure you include the error details and the output of uname -r


# Stage 1 of the script, create the sandbox that we will be working within

clear
mkdir /home/ben/AVUpdate
cd /home/ben/AVUpdate

# Stage 1 ends

# Stage 2 of the script, clear the screen and then download the manifest from the remote server

wget http://kav.zonelabs.com/bases/five/avc/kavset.xml

# Stage 2 Ends

# Stage 3

# We only need certain lines from the file, we don't know how many occurences there will be, but we do know that
# they will all start with Filename= so lets grep those out

cat kavset.xml | grep Filename= > kavset.parse1


# Stage 4, this is where things get a bit more clever. We need to use sed to parse out Filename= and replace it 
# with the beginning of the Web Address.

sed -i.old "s/Filename=/http\:\/\/kav.zonelabs.com\/bases\/five\/avc\//g" kavset.parse1

# This will give us lines looking like http://kav.zonelabs.com/bases/five/avc/"kernel.avc"
# Whilst this works, it looks a bit messy so lets remove the quotation marks

sed -i.old "s/\"//g" kavset.parse1

# This looks much better http://kav.zonelabs.com/bases/five/avc/kernel.avc

# Stage 4 Ends


# Stage 5

# We now have a parsed list of files, but this is useless to Zonealarm, so we need to actually fetch
# the virus signatures from the server.

echo "Ok Fetching the files, this could take quite a while"

wget --input-file=kavset.parse1

# Stage 5 ends


# Stage 6

# Now we get rid of the files that we have created, or at least the ones not needed by Zonealarm

rm kavset.parse1

# Stage 6 ends


# Stage 7

# We could archive the files into a Zip file with the following command

# zip * AVUpdate.zip

# but for convenience of processing on the standalone we won't


# Stage 8 (The last bit) 

# Lets move the Database to somewhere that we will find it

cd ..
mv AVUpdate /home/ben/Desktop/

exit

# Done!!

