#!/bin/bash

DAYSDIFF="60"
DATADIR="/var/lib/clamav"
[ "$DATABASEFILE" ] || DATABASEFILE="$DATADIR/daily.cvd"
[ "$SIGTOOL" ] || SIGTOOL="`which sigtool`"

if ! [ -e /var/lib/clamav-data/warn-on-old-databases ]; then
  # user doesn't want to see warning
  exit 0
fi

if [ -z "$SIGTOOL" ] || ! [ -x "$SIGTOOL" ]; then
  # no sigtool present, clamav uninstalled
  exit 0
fi

if ! [ -e "$DATABASEFILE" ]; then
  # no database file present, package removed but not purged
  exit 0
fi

if ! [ -e "$DATABASEFILE" ]; then
  echo >&2 "ERR: $DATABASEFILE does not exist."
  echo >&2 "     This should not happen since that file is part of the"
  echo >&2 "     clamav-data package."
  exit 1
fi

FILEDATE="$($SIGTOOL --stdout --info=$DATADIR/daily.cvd |\
            sed -n '/^Build time:/{s/Build time: //;/^[[:alnum:]]\{3\}-[[:digit:]]\{2\} [[:digit:]]\{2\}-[[:digit:]]\{2\}/s/-/ /;s/-/:/;p;}')"
DBDATE="`date --utc --date="$FILEDATE" +%s`"
REFDATE="`date --utc --date="$DAYSDIFF days ago" +%s`"

if [ $DBDATE -lt $REFDATE ]; then
  cat >&2 <<EOF
The clamav-data package that is installed does contain databases older
than $DAYSDIFF days. This can give you a false sense of security since
your clamav scanner will not detect any malicious code that has been found
since then.

Please update your clamav-data package at your earliest convenience. On a
host with good Internet connectivity, you can install the package
clamav-freshclam, which will pull current clamav databases from the Internet
on a regular basis. Or you can run clamav-getfiles from the clamav-getfiles
package to create an up-to-date clamav-data package.

If you do not want to receive these e-mails any more, please run
dpkg-reconfigure clamav-data and turn off the reminder e-mails.
EOF
fi

# end of file
