#!/bin/sh

. /etc/rc.common

StartService ()
{
    if [ "${MAILTRANSPORT:=-NO-}" = "-YES-" ]; then
	ConsoleMessage "Starting MAILTRANSPORT"
	freshclam -d
	clamd
	su mailtransport -c amavisd
	else
	NoService
	fi
}

StopService ()
{
	ConsoleMessage "Stoping MAILTRANSPORT"
	if [ -f /var/clamav/clamd.pid ]; then kill -9 $(head -1 /var/clamav/clamd.pid);fi
	if [ -f /var/clamav/freshclam.pid ]; then kill -9 $(head -1 /var/clamav/freshclam.pid);fi
	if [ -f /var/amavis/amavisd.pid ]; then amavisd stop;fi
}

RestartService ()
{
    if [ "${MAILTRANSPORT:=-NO-}" = "-YES-" ]; then
	ConsoleMessage "Reloading MAILTRANSPORT"
	StopService
	StartService
    else
	StopService
	NoService
	fi
}

NoService ()
{
	ConsoleMessage "Service is disabled in /etc/hostconfig
	
	Unable to start
	"
}

RunService "$1"
