#!/bin/sh # # $NetBSD: update_dat,v 1.3 2001/09/27 07:55:18 rh Exp $ # # Script to update the VirusScan data files. UVSCANDIR=@PREFIX@/libexec/uvscan DAT_SITE=http://download.nai.com/products/datfiles/4.x/nai DAT_FILES="@DATFILES@" TMPDIR=${TMPDIR:-/tmp}/$$ if [ "$1" = "-v" ]; then verbose=1 shift fi [ -z "$1" ] || DAT_SITE="$1" mkdir -p ${TMPDIR} mkdir -p ${UVSCANDIR} cd ${TMPDIR} # Fetch the ReadMe file to read the latest version of the DAT files. if ! ( ftp ${DAT_SITE}/readme.txt >/dev/null ) then echo "$0: unable to fetch ${DAT_SITE}/readme.txt" rm -rf ${TMPDIR} exit 1 fi CURVER=`head -n 2 readme.txt | grep DAT | sed -e 's/^.*\([0-9][0-9][0-9][0-9]\).*$/\1/'` OLDVER=`head -n 2 ${UVSCANDIR}/readme.txt | grep DAT | sed -e 's/^.*\([0-9][0-9][0-9][0-9]\).*$/\1/'` exitcode=0 if [ "${CURVER}" = "${OLDVER}" ] then [ -z "$verbose" ] || echo "$0: VirusScan DAT files are current (${CURVER})" else DAT_TAR=dat-${CURVER}.tar if ftp ${DAT_SITE}/${DAT_TAR} >/dev/null then if tar xf ${DAT_TAR} ${DAT_FILES} then # Backup old dat-* tar files. if [ "`echo ${UVSCANDIR}/*.tar`" != "${UVSCANDIR}/*.tar" ] then for file in ${UVSCANDIR}/*.tar do rm -f ${file}.old mv ${file} ${file}.old done fi # Backup old DAT files. for file in ${DAT_FILES} do file=${UVSCANDIR}/${file} if [ -f ${file} ] then rm -f ${file}.bak mv ${file} ${file}.bak fi done # Copy new DAT files into place. for file in ${DAT_FILES} do cp -p ${file} ${UVSCANDIR}/${file} done cp -p ${DAT_TAR} ${UVSCANDIR}/${DAT_TAR} rm -f ${UVSCANDIR}/*.old echo `date` Successfully updated VirusScan DAT files to ${CURVER}. else echo "$0: unable to update VirusScan DAT files" exitcode=1 fi else echo "$0: unable to fetch ${DAT_SITE}/${DAT_TAR}" exitcode=1 fi fi cd / rm -rf ${TMPDIR} exit ${exitcode}