#!/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