#!/bin/sh

##
# PrintingServices - a.k.a. CUPS
##

. /etc/rc.common

StartService ()
{
	if [ "${CUPS:=-AUTOMATIC-}" = "-AUTOMATIC-" ]; then
		ConsoleMessage "Starting printing services"
		/usr/sbin/cupsd -L
	elif [ "${CUPS:=-AUTOMATIC-}" = "-YES-" ]; then
		ConsoleMessage "Starting printing services"
		/usr/sbin/cupsd
	fi
}

StopService ()
{
	# Until cupsd has a pid file...
	pid=`ps ax | awk '{if (match($5, ".*/cupsd$") || $5 == "cupsd") print $1}'`
	if test "$pid" != ""; then
		ConsoleMessage "Stopping printing services"
		kill "${pid}"
	fi
}

RestartService ()
{
	# Until cupsd has a pid file...
	pid=`ps ax | awk '{if (match($5, ".*/cupsd$") || $5 == "cupsd") print $1}'`
	if test "x$pid" != x; then
		ConsoleMessage "Restarting printing services"
		kill -HUP "${pid}"
	else
		if [ "${CUPS:=-AUTOMATIC-}" = "-AUTOMATIC-" -o "${CUPS:=-AUTOMATIC-}" = "-YES-" ]; then
			ConsoleMessage "Starting printing services"
			/usr/sbin/cupsd
		fi
	fi
}

RunService "$1"
