aboutsummaryrefslogtreecommitdiff
blob: 7ff73597447a5eb70496cffa7b774e49db0a8c8c (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/bash
set -e

if [ ! -d data ]; then
	echo "run in main directory (the one with bin and data subdirectories)" >&2
	exit 1
fi

TEMP=`getopt -o fqv --long full,quiet,verbose  -n 'update' -- "$@"`

if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

FULL=""
#MAIL=""
QUIET=""
VERB="-nv"

while true ; do
	case "$1" in
		-f|--full)    FULL="1"  ; shift ;;
#		-m|--mail)    MAIL="1"  ; shift ;;
		-q|--quiet)   QUIET="1" VERB="-q" ; shift ;;
		-v|--verbose) VERB=""   ; shift ;;
		--) shift ; break ;;
		*) echo "Internal error." ; exit 1 ;;
	esac
done

if [ -n "${QUIET}" ] ; then
	# stdout = null
	exec 1<>/dev/null
fi


# Update all cached files
mkdir -p cache/download.tmp
cd cache/download.tmp

echo "[DOWNLOAD] MITRE Master database"
wget ${VERB} http://cve.mitre.org/data/downloads/allitems.html.gz
gunzip allitems.html.gz
mv allitems.html ..

YEARS='modified'
if [ -n "${FULL}" ] ; then
	YEAR=`date +"%Y"`
	YEARS="$YEARS `seq ${YEAR} -1 2002`"
fi

echo "==============================================================================="
for yr in $YEARS; do
	echo "[DOWNLOAD] NVD Database '$yr'"
	cp ../nvdcve-$yr.xml . 2>/dev/null || touch nvdcve-$yr.xml
	wget --timestamping ${VERB} http://nvd.nist.gov/download/nvdcve-$yr.xml && mv nvdcve-$yr.xml ..
done

cd ..
rmdir download.tmp

echo "==============================================================================="
echo "[UPDATE] Updating our CVE data"
NEWLIST="$(mktemp -t cveupdate.XXXXXXXXX)"

# Run the update script
cd ../data/CVE/
../../bin/updatelist ../../cache/allitems.html ../../cache/nvdcve-modified.xml list > "${NEWLIST}"

echo "==============================================================================="
echo "[DIFF] New and updated CVE entries"
diff -u list ${NEWLIST} || true
mv -f "${NEWLIST}" list

cd ../../
./bin/check-todo-issues -s > /dev/null