File: update-eicar

package info (click to toggle)
clamav-getfiles 0.7-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 272 kB
  • ctags: 4
  • sloc: sh: 402; makefile: 99; perl: 13
file content (126 lines) | stat: -rwxr-xr-x 3,159 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
# Download and install the EICAR Anti-Virus test file from the Internet
#
# (C) 2003 Marc Haber
# This script has been derived from update-ms-fonts by Eric Sharkey
# You may freely distribute this file under the terms of the GNU General
# Public License, version 2 or later.

#abort if anything goes wrong
set -e

if [ `id -u` != 0 ] ; then
  echo "update-eicar can only be run as root."
  exit -1
fi

for x in $* ; do
  if [ `echo $x | awk '{print substr($1,1,1)}'` = '-' ] ; then
    case `echo $x | awk '{print substr($1,2,1)}'` in
      q) QUIET_MODE=1;;
      c) CHECK_ONLY=1;;
    esac
  else
    LOCALCOPY=$x
  fi
done

if [ `echo $LOCALCOPY | tr [:upper:] [:lower:] `x = "nonex" ] ; then
  exit 0
fi

EXITCODE=0

URLROOT="http://www.eicar.org/download"
LOCALTARGETDIR="/var/lib/clamav-getfiles"
SCRATCHDIR=/tmp/clamav-getfiles

if [ "$SCRATCHDIR" = "$LOCALCOPY" ] ; then
  SCRATCHDIR=/tmp/clamav-getfiles-scratch
fi

mkdir -p -m 0755 $SCRATCHDIR
if [ -O $SCRATCHDIR ] ; then
  if [ `ls -ld $SCRATCHDIR | awk '{print substr($1,6,1) substr($1,9,1)}'` != '--' ] ; then
    echo "
update-eicar: Error: $SCRATCHDIR must have mode 755 permissions.

The directory $SCRATCHDIR is writable by non-root users.  Using this
directory would be a security risk.  Please remove this directory.
" 1>&2
    exit -3;
  fi
else
  echo "
update-eicar: Error: $SCRATCHDIR is not owned by root.

The directory $SCRATCHDIR exists but is not owned by root with group
root.  Using this directory would be a security risk.  Please remove it.
" 1>&2
  exit -2;
fi
cd $SCRATCHDIR

INFOFILE="eicar.info"

cat <<EOF > $INFOFILE
44d88612fea8a8f36de82e1278abb02f  eicar.com
EOF

for file in `awk '{print $2}' $INFOFILE` ; do
  if [ ! -e $LOCALTARGETDIR/$file ] || [ `md5sum $LOCALTARGETDIR/$file | awk '{print $1}'` != `grep $file $INFOFILE | awk '{print $1}'` ] ; then
    THISFILE=`grep $file $INFOFILE | awk '{print $2}'`
    echo "$file md5sum mismatch, file needs downloading"
    if ! echo $DWNLDFILES | grep -q $THISFILE ; then
      DWNLDFILES="$DWNLDFILES $THISFILE"
    fi
  fi
done

mkdir -p $LOCALTARGETDIR

if [ -n "$CHECK_ONLY" ] ; then
  if [ -n "$DWNLDFILES" ] ; then
    EXITCODE=1
  fi
elif [ -n "$DWNLDFILES" ] ; then 
  for ff in $DWNLDFILES; do
    if [ ! -e $ff.done ] || [ ! -e $ff ] ; then
      if [ -z "$LOCALCOPY" ] ; then
        if [ -n "$QUIET_MODE" ] ; then
          curl --quiet --remote-name $URLROOT/$ff
        else
	  echo curl --remote-name $URLROOT/$ff
          curl --remote-name $URLROOT/$ff
        fi
      else
        cp $LOCALCOPY/$ff .
      fi
      cp $ff $LOCALTARGETDIR
      touch $ff.done
    fi
  done
  #Add some level of predictability by folding everything to lower case
  for x in *; do
    y=`echo $x | tr '[A-Z]' '[a-z]'`
    if [ "$x" != "$y" ]; then
       mv "$x" "$y"
    fi
  done

  chmod 644 *

  awk '{print $2}'  $INFOFILE > /var/lib/clamav-getfiles/installedfiles
fi

rm -rf $SCRATCHDIR

if [ -z "$QUIETMODE" ] ; then
  if [ $EXITCODE = 0 ] ; then
    echo "EICAR Anti-Virus Test File downloaded and installed."
  else
    echo "EICAR Anti-Virus Test File needs to be updated."
  fi
fi

exit $EXITCODE