summaryrefslogtreecommitdiff
path: root/security/uvscan-dat/files/update_dat
blob: b8449a0b523ab68deda1d351855815de4f79e2f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
#
# $NetBSD: update_dat,v 1.2 2001/08/16 00:01:25 jlam 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}/$$

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 -1 readme.txt | cut -d' ' -f11`
OLDVER=`head -1 ${UVSCANDIR}/readme.txt | cut -d' ' -f11`
exitcode=0
if [ "${CURVER}" = "${OLDVER}" ]
then
	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}