Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions clamav.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,44 @@
#
# !!! To receive best protection, you should setup a cronjob that executes this script every minute !!!
#
# This script requires the lockfile command provided by procmail
#
# Please set up the following variables to fit your system

CLAMDIR="/var/lib/clamav"
CLAMUSER="clamav"
CLAMGROUP="clamav"
LOCKFILE="/tmp/urlhaus.lock"
TEMPDIR="/tmp/urlhaus/"

# Don't change anything below this line

RELOAD=0

lockfile -r 0 /tmp/local.the.lock 2>/dev/null || exit 1
lockfile -r 0 $LOCKFILE 2>/dev/null || exit 1

rm -rf /tmp/urlhaus
mkdir /tmp/urlhaus
rm -rf $TEMPDIR
mkdir $TEMPDIR

curl -s https://urlhaus.abuse.ch/downloads/urlhaus.ndb -o /tmp/urlhaus/urlhaus.ndb
curl -s https://urlhaus.abuse.ch/downloads/urlhaus.ndb -o $TEMPDIR/urlhaus.ndb

if [ $? -eq 0 ]; then
clamscan --quiet -d /tmp/urlhaus /tmp/urlhaus 2>&1 >/dev/null
clamscan --quiet -d $TEMPDIR $TEMPDIR 2>&1 >/dev/null
if [ $? -eq 0 ]; then
if [ -f "$CLAMDIR"/urlhaus.ndb ]; then
MD5old=`md5sum "$CLAMDIR"/urlhaus.ndb`
MD5new=`md5sum /tmp/urlhaus/urlhaus.ndb`
if ! [ "$MD5old" = "$MD5new" ]; then
MD5old=$(md5sum "$CLAMDIR"/urlhaus.ndb | awk '{print $1}')
MD5new=$(md5sum $TEMPDIR/urlhaus.ndb | awk '{print $1}')
echo $MD5old
echo $MD5new
if [ "$MD5old" != "$MD5new" ]; then
# Updated file
cp /tmp/urlhaus/urlhaus.ndb $CLAMDIR
cp $TEMPDIR/urlhaus.ndb $CLAMDIR
chown $CLAMUSER.$CLAMGROUP "$CLAMDIR"/urlhaus.ndb
RELOAD=1
fi
else
# Looks like it's the first run
cp /tmp/urlhaus/urlhaus.ndb $CLAMDIR
cp $TEMPDIR/urlhaus.ndb $CLAMDIR
chown $CLAMUSER.$CLAMGROUP "$CLAMDIR"/urlhaus.ndb
RELOAD=1
fi
Expand All @@ -46,5 +52,5 @@ if [ $RELOAD -eq 1 ]; then
clamdscan --reload
fi

rm -rf /tmp/urlhaus
rm -f /tmp/local.the.lock
rm -rf $TEMPDIR
rm -f $LOCKFILE