#! /bin/sh
#	$Id: hylafax.in,v 1.12 2008/04/28 20:37:05 aidan Exp $
#
# chkconfig: 2345 97 05
#
# description: HylaFAX(tm) is a sophisticated enterprise-strength fax
#              package for class 1 and 2 fax modems on unix systems.
#              This init script is the preferred way to start HylaFAX,
#              but does not, by default, activate any modems. Consult
#              the faxgetty(8) and faxmodem(8) man pages for more info.
#
# Warning, this file was automatically created by the HylaFAX configure script
#
# HylaFAX Facsimile Software
#
# Copyright (c) 1990-1996 Sam Leffler
# Copyright (c) 1991-1996 Silicon Graphics, Inc.
# HylaFAX is a trademark of Silicon Graphics
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.

#
# VERSION:	6.0.2
# DATE:		Wed Jul 29 09:47:51 UTC 2009
# TARGET:	i386-suse-linux
#

#
# fax server control
#
# NB: This script assumes faxgetty processes are managed by init
#
### BEGIN INIT INFO
# Provides:		hylafax
# Required-Start:	$remote_fs
# Should-Start:		ypbind isdn
# Required-Stop:	$remote_fs
# Should-Stop:		ypbind isdn
# Default-Start:	3 5
# Default-Stop:		0 1 2 6
# Description:		Start HylaFax fax server daemon
### END INIT INFO

. /etc/rc.status
SPOOL=/var/spool/hylafax

test -f $SPOOL/etc/setup.cache || {
    cat<<EOF

FATAL ERROR: $SPOOL/etc/setup.cache is missing!

The file $SPOOL/etc/setup.cache is not present.  This
probably means the machine has not been setup using the faxsetup(M1)
command.  Read the documentation on setting up HylaFAX before you
startup a server system.

EOF
    exit 1
}
. $SPOOL/etc/setup.cache

if [ -z $HFAXD_SERVER ]; then
    HFAXD_SERVER=1
fi
if [ -z $FAXQ_SERVER ]; then
    FAXQ_SERVER=1
fi

IS_ON=/etc/chkconfig		# NB: chkconfig is IRIX- and Linux-specific
FAXQ=/usr/sbin/faxq
HFAXD=/usr/lib/fax/hfaxd
FAXQUIT=/usr/sbin/faxquit
KILLALL=/usr/bin/killall
FAXPORT=hylafax			# designated port for new protocol
SNPPPORT=444			# official port for SNPP

if test ! -x $IS_ON ; then
    IS_ON=true
fi

if $IS_ON verbose ; then
    ECHO="echo -e"
else		# For a quiet startup and shutdown
    ECHO=:
fi

# The echo return value for success (defined in /etc/rc.config).
return=$rc_done

case $1 in
start)
	if $IS_ON hylafax && test -x $FAXQ; then
		echo -n "Starting service HylaFAX"
		killall -15 $FAXQ >/dev/null 2>&1
		killall -15 $HFAXD >/dev/null 2>&1
		/sbin/startproc $FAXQ || return $rc_failed
		/sbin/startproc $HFAXD -i $FAXPORT -o 4557 -s $SNPPPORT \
			||  return=$rc_failed
		echo -e "$return"
	fi
	;;
stop)
	echo -n "Shutting down service HylaFAX"
	$FAXQUIT >/dev/null 2>&1
	/sbin/killproc -TERM $HFAXD || return=$rc_failed
	echo -e "$return"
	;;
restart)
	$0 stop && $0 start || return=$rc_failed
	;;
reload)
	$0 stop && $0 start || return=$rc_failed
	;;
status)
	echo -n "Checking for service HylaFAX: "
	## Check status with checkproc(8), if process is running
	## checkproc will return with exit status 0
	echo -n "HylaFAX queue manager process: "
	/sbin/checkproc $FAXQ
	rc_status -v
	echo -n "HylaFAX client-server protocol server: "
	/sbin/checkproc $HFAXD
	rc_status -v
	;;
*)
	echo "Usage: /etc/init.d/hylafax {start|stop|restart|reload|status}"
	;;
esac

rc_exit

