summaryrefslogtreecommitdiff
path: root/packages/clamav/files/clamav-freshclam.init
blob: 490a41e31f0da6b7f4df9b371c74cfae5bb8a06a (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
78
79
80
81
82
83
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/freshclam
NAME=freshclam
DESC="ClamAV virus database updater"
CLAMAV_CONF_FILE=/etc/clamd.conf
FRESHCLAM_CONF_FILE=/etc/freshclam.conf
pidfile=/var/run/clamav/freshclam.pid

set -e

test -r /etc/default/clamav-freshclam && . /etc/default/clamav-freshclam
test -x "$DAEMON" || exit 0
test ! -r "$CLAMAV_CONF_FILE" && exit 0

slurp_config()
{
  CLAMAVCONF="$1"

  if [ -e "$CLAMAVCONF" ]; then
    for variable in `egrep -v '^[[:space:]]*(#|$)' "$CLAMAVCONF" | awk '{print $1}'`; do
      if [ "$variable" = 'DatabaseMirror' ]; then
        if [ -z "$DatabaseMirror" ]; then
          for i in `grep ^$variable $CLAMAVCONF | awk '{print $2}'`; do
            value="$i $value"
          done
        else
          continue
        fi
      elif [ "$variable" = 'VirusEvent' -o "$variable" = 'OnUpdateExecute' -o "$variable" = 'OnErrorExecute' ]; then
        value=`grep ^$variable $CLAMAVCONF | head -n1 | sed -e s/$variable\ //`
      else
        value=`grep ^$variable $CLAMAVCONF | head -n1 | awk '{print $2}'`
      fi
      if ! [ "$value" = "$variable" -o "$value" = "" ]; then
        export "$variable"="$value"
      else
        export "$variable"="true"
      fi
      unset value
    done
  fi
}

slurp_config "$FRESHCLAM_CONF_FILE"

[ -z "$UpdateLogFile" ] && UpdateLogFile=/var/log/clamav/freshclam.log

if [ -z "$DatabaseDirectory" ]; then
  [ -r "$CLAMAV_CONF_FILE" ] && DatabaseDirectory=$(grep 'DataDirectory' "$CLAMAV_CONF_FILE" | awk '{print $2}')
  [ -z "$DatabaseDirectory" ] && DatabaseDirectory=/var/lib/clamav/
fi


case "$1" in
  no-daemon)
    echo "It takes freshclam ~3min to timeout and try the next mirror in the list"
    freshclam -l "$UpdateLogFile" --datadir "$DatabaseDirectory"
    ;;

  start)
    echo -n "Starting $DESC: "
    start-stop-daemon -S -x $DAEMON -- -d --quiet -p $pidfile
    echo "$NAME."
    ;;

  stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon -K -p $pidfile
    ;;

  restart|force-reload)
    $0 stop
    $0 start
    ;;

  *)
    echo "Usage: $0 {no-daemon|start|stop|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0