#!/bin/sh
# launchFaxDB.sh
# 
. /etc/rc.common 

StartService ()
{
OSVERSION="$(sw_vers -productVersion)"
MAJOR="$(echo $OSVERSION | sed 's/\..*//')"
MINOR="$(echo $OSVERSION | sed -E 's/[0-9]+\.([0-9]+)\..*/\1/')"
PATCH="$(echo $OSVERSION | sed -E 's/[0-9]+\.[0-9]+\.([0-9]+).*/\1/')"

if [ $MAJOR -eq 10 ] ; then
        if [ $MINOR -le 3 ] 
		 then
                ConsoleMessage "Starting Samsung MFP Fax serice"
				/Library/Printers/Samsung/Fax/FaxDB/faxdbd &
        fi
fi

}

StopService ()
{
	pid=`ps ax | awk '{if (match($5, ".*/faxdbd$") || $5 == "faxdbd") print $1}'`
	ConsoleMessage "Stop FaxDB pid=$pid"
	if test "$pid" != "" ; then
		ConsoleMessage "Stopping Samsung MFP fax service"
		kill "${pid}"
	fi
}

RestartService ()
{
	pid=`ps ax | awk '{if (match($5, ".*/faxdbd$") || $5 == "faxdbd") print $1}'`
	ConsoleMessage "Restart FaxDB pid=$pid"
	if test "x$pid" != x ; then
		ConsoleMessage "Restart Samsung MFP fax service"
		kill -HUP "${pid}"
	else
		StartService
	fi
}

RunService "$1"