#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/clamd
NAME="clamd"
DESC="ClamAV daemon"
CLAMAVCONF=/etc/clamd.conf

set -e

test -r /etc/default/clamav-daemon && . /etc/default/clamav-daemon
test -x "$DAEMON" || exit 0
test ! -r "$CLAMAVCONF" && exit 0
if [ `grep -q "^Example" $CLAMAVCONF` ]; then
    echo "$DESC is not configured."
    exit 0
fi
pidfile="`grep ^PidFile $CLAMAVCONF | awk '{print $2}'`"

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start-stop-daemon --oknodo -S -x $DAEMON
    echo "$NAME."
    ;;

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

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

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

exit 0