--- clamd.old 2011-12-04 13:51:46.000000000 +0200 +++ clamd.rc 2012-08-07 16:26:45.778188429 +0300 @@ -10,14 +10,31 @@ 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==\"\")exit + if(S==1&&\$1~\"^$2\$\"){ + print \$2!=\"disabled\"?\$2:\"$3\"; + exit + } + }" +} +start() { + local clamd_socket=$(get_config clamd LocalSocket /tmp/clamd) + local clamd_socket_dir=`dirname ${clamd_socket}` logfix if [ "${START_CLAMD}" = "yes" ]; then - if [ -S "${clamd_socket:-/tmp/clamd}" ]; then - rm -f ${clamd_socket:-/tmp/clamd} + if [ ! -e "${clamd_socket_dir}" ]; then + mkdir ${clamd_socket_dir} + chown $(get_config clamd User clamav) ${clamd_socket_dir} + fi + if [ -S "${clamd_socket}" ]; then + rm -f ${clamd_socket} fi ebegin "Starting clamd" start-stop-daemon --start --quiet \ @@ -75,8 +92,8 @@ 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` + local logfile=$(get_config clamd LogFile) + local clamav_user=$(get_config clamd User) if [ -n "${logfile}" ] && [ -n "${clamav_user}" ]; then if [ ! -f "${logfile}" ]; then touch ${logfile} @@ -89,8 +106,8 @@ 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` + local logfile=$(get_config freshclam UpdateLogFile) + local freshclam_user=$(get_config freshclam DatabaseOwner clamav) if [ -n "${logfile}" -a -n "${clamav_user}" ]; then if [ ! -f "${logfile}" ]; then touch ${logfile}