#!/bin/sh
#
# $MidnightBSD: mports/security/clamav/files/clamav-clamd.in,v 1.6 2013/06/21 00:51:14 laffer1 Exp $
#

# PROVIDE: clamd
# REQUIRE: LOGIN
# BEFORE: mail
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable clamd:
#
# clamav_clamd_enable="YES"
# clamav_clamd_flags="<set as needed>"
#
# See clamd(8) for flags
#

. /etc/rc.subr

name=clamav_clamd
rcvar=clamav_clamd_enable

command=/usr/local/sbin/clamd
required_dirs=/var/db/clamav
required_files=/usr/local/etc/clamd.conf

# read settings, set default values
load_rc_config "$name"
: ${clamav_clamd_enable="NO"}
: ${clamav_clamd_socket="/var/run/clamav/clamd.sock"}

start_precmd=clamav_clamd_precmd

#clamav .93 won't start without a valid main.c[vl]d file
clamav_clamd_precmd() {
	if [ ! -f /var/db/clamav/main.cvd -a ! -f /var/db/clamav/main.cld ];then
		echo "Missing /var/db/clamav/clamav/*.cvd or *.cld files.  You must run freshclam first"
		exit 1
	fi
}

extra_commands="reload"
reload_cmd=clamd_reload

clamd_reload()
{
  /usr/local/bin/clamdscan --reload
}

run_rc_command "$1"
