#!/sbin/runscript
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/app-antivirus/clamav/files/clamd.rc,v 1.18 2011/12/04 11:51:46 swegener Exp $
+# $Header: /var/cvsroot/gentoo-x86/app-antivirus/clamav/files/clamd.initd,v 1.2 2012/08/11 13:12:35 eras Exp $
+
+daemon_clamd="/usr/sbin/clamd"
+daemon_freshclam="/usr/bin/freshclam"
+daemon_milter="/usr/sbin/clamav-milter"
extra_commands="logfix"
provide antivirus
}
-start() {
- local clamd_socket=`awk '$1 == "LocalSocket" { print $2 }' /etc/clamd.conf`
+get_config() {
+ clamconf | sed 's/["=]//g' | \
+ awk "{
+ if(\$0==\"Config file: $1.conf\") S=1
+ if(S==1&&\$0==\"\") {
+ print \"$3\"
+ exit
+ }
+ if(S==1&&\$1~\"^$2\$\") {
+ print \$2!=\"disabled\"?\$2:\"$3\"
+ exit
+ }
+ }"
+}
+start() {
+ local clamd_socket=$(get_config clamd LocalSocket /tmp/clamd)
logfix
if [ "${START_CLAMD}" = "yes" ]; then
- if [ -S "${clamd_socket:-/tmp/clamd}" ]; then
- rm -f ${clamd_socket:-/tmp/clamd}
+ checkpath --quiet \
+ --owner $(get_config clamd User clamav):root \
+ --directory `dirname ${clamd_socket}`
+ if [ -S "${clamd_socket}" ]; then
+ rm -f ${clamd_socket}
fi
ebegin "Starting clamd"
start-stop-daemon --start --quiet \
--nicelevel ${CLAMD_NICELEVEL:-0} \
- --exec /usr/sbin/clamd
+ --exec ${daemon_clamd}
eend $? "Failed to start clamd"
fi
ebegin "Starting freshclam"
start-stop-daemon --start --quiet \
--nicelevel ${FRESHCLAM_NICELEVEL:-0} \
- --exec /usr/bin/freshclam -- -d
+ --exec ${daemon_freshclam} -- -d
retcode=$?
if [ ${retcode} = 1 ]; then
eend 0
ebegin "Starting clamav-milter"
start-stop-daemon --start --quiet \
--nicelevel ${MILTER_NICELEVEL:-0} \
- --exec /usr/sbin/clamav-milter -- -c ${MILTER_CONF_FILE}
+ --exec ${daemon_milter} -- -c ${MILTER_CONF_FILE}
eend $? "Failed to start clamav-milter"
fi
}
if [ "${START_CLAMD}" = "yes" ]; then
# fix clamd log permissions
# (might be clobbered by logrotate or something)
- local logfile=`awk '$1 == "LogFile" { print $2 }' /etc/clamd.conf`
- local clamav_user=`awk '$1 == "User" { print $2 }' /etc/clamd.conf`
- if [ -n "${logfile}" ] && [ -n "${clamav_user}" ]; then
- if [ ! -f "${logfile}" ]; then
- touch ${logfile}
- fi
- chown ${clamav_user} ${logfile}
- chmod 640 ${logfile}
+ local logfile=$(get_config clamd LogFile)
+ if [ -n "${logfile}" ]; then
+ checkpath --quiet \
+ --owner $(get_config clamd User clamav):root \
+ --mode 640 \
+ --file ${logfile}
fi
fi
if [ "${START_FRESHCLAM}" = "yes" ]; then
# fix freshclam log permissions
# (might be clobbered by logrotate or something)
- logfile=`awk '$1 == "UpdateLogFile" { print $2 }' /etc/freshclam.conf`
- local freshclam_user=`awk '$1 == "DatabaseOwner" { print $2 }' /etc/freshclam.conf`
- if [ -n "${logfile}" -a -n "${clamav_user}" ]; then
- if [ ! -f "${logfile}" ]; then
- touch ${logfile}
- fi
- chown ${freshclam_user} ${logfile}
- chmod 640 ${logfile}
+ local logfile=$(get_config freshclam UpdateLogFile)
+ if [ -n "${logfile}" ]; then
+ checkpath --quiet \
+ --owner $(get_config freshclam DatabaseOwner clamav):root \
+ --mode 640 \
+ --file ${logfile}
fi
fi
}