--- etc/hylafax.in.orig	2009-07-02 23:13:53.000000000 +0200
+++ etc/hylafax.in	2009-07-02 23:24:50.000000000 +0200
@@ -47,6 +47,18 @@
 #
 # 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=@SPOOL@
 
 test -f $SPOOL/etc/setup.cache || {
@@ -55,7 +67,7 @@ test -f $SPOOL/etc/setup.cache || {
 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(@MANNUM1_8@)
+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.
 
@@ -64,21 +76,18 @@ EOF
 }
 . $SPOOL/etc/setup.cache
 
-# Just in case these are not in setup.cache yet
-if [ -z "$HFAXD_SERVER" ]; then
-    HFAXD_SERVER=@HFAXD_SERVER@
-fi
-if [ -z "$FAXQ_SERVER" ]; then
-    FAXQ_SERVER=@FAXQ_SERVER@
+if [ -z $HFAXD_SERVER ]; then
+    HFAXD_SERVER=1
 fi
-if [ -z "$HFAXD_SNPP_SERVER" ]; then
-    HFAXD_SNPP_SERVER=@HFAXD_SNPP_SERVER@
+if [ -z $FAXQ_SERVER ]; then
+    FAXQ_SERVER=1
 fi
 
 IS_ON=/etc/chkconfig		# NB: chkconfig is IRIX- and Linux-specific
-FAXQ=$SBIN/faxq
-HFAXD=$LIBEXEC/hfaxd
-FAXQUIT=$SBIN/faxquit
+FAXQ=@SBIN@/faxq
+HFAXD=@LIBEXEC@/hfaxd
+FAXQUIT=@SBIN@/faxquit
+KILLALL=/usr/bin/killall
 FAXPORT=hylafax			# designated port for new protocol
 SNPPPORT=444			# official port for SNPP
 
@@ -87,116 +96,53 @@ if test ! -x $IS_ON ; then
 fi
 
 if $IS_ON verbose ; then
-    ECHO=echo
+    ECHO="echo -e"
 else		# For a quiet startup and shutdown
     ECHO=:
 fi
 
-#
-# Figure out which brand of echo we have and define prompt
-# and printf shell functions accordingly.  Note that we
-# assume that if the System V-style echo is not present,
-# then the BSD printf program is available.  These functions
-# are defined here so that they can be tailored on a per-site,
-# etc. basis.
-#
-if [ `echo foo\\\c`@ = "foo@" ]; then
-    # System V-style echo supports \r
-    # and \c which is all that we need
-    printf()
-    {
-       $ECHO "$*\\c"
-    }
-elif [ "`echo -n foo`@" = "foo@" ]; then
-    # BSD-style echo; use echo -n to get
-    # a line without the trailing newline
-    printf()
-    {
-       $ECHO -n "$*"
-    }
-else
-    # something else; do without
-    printf()
-    {
-	$ECHO "$*"
-    }
-fi
-
-#
-#
-# killall -SIGNAL process-name
-#
-# Emulate the necessary functionality of the
-# killall program
-#
-killall()
-{
-	# NB: ps ax should give an error on System V, so we try it first!
-	pid="`ps ax 2>/dev/null | $AWK \"\
-		/[\/ (]$2[ )]/	{print \\$1;}
-		/[\/ ]$2\$/	{print \\$1;}\"`"
-	test "$pid" ||
-	    pid="`ps -e 2>/dev/null | $AWK \"/ $2[ ]*\$/ {print \\$1;}\"`"
-	test "$pid" && kill $1 $pid; return
-}
-
-do_start()
-{
-	if $IS_ON fax && test -x $FAXQ; then
-	    if test $FAXQ_SERVER = yes ; then
-		killall -15 faxq
-	    fi
-	    if test $HFAXD_SERVER = yes ; then
-		killall -15 hfaxd
-	    fi
-	    printf "HylaFAX:"
-            if test $FAXQ_SERVER = yes ; then
-	        $FAXQ; printf " faxq"
-            fi
-            if test $HFAXD_SERVER = yes ; then
-	        HFAXD="$HFAXD -i $FAXPORT"
-		HFAXMSG=" hfaxd"
-		if [ $HFAXD_SNPP_SERVER = yes ]; then
-	    	    HFAXD="$HFAXD -s $SNPPPORT"
-		    HFAXMSG="$HFAXMSG (with SNPP support)"
-		else
-		    HFAXMSG="$HFAXMSG (without SNPP support)"
-		fi
-		$HFAXD ; printf "$HFAXMSG"
-            fi
-	    if test $FAXQ_SERVER != yes && test $HFAXD_SERVER != yes ; then
-		printf " not started (script disabled by configure)"
-	    fi
-	    $ECHO "."
-	fi
-}
-
-do_stop ()
-{
-    $ECHO "Stopping HylaFAX Servers."
-    $FAXQUIT >/dev/null 2>&1
-    killall -15 hfaxd
-}
+# The echo return value for success (defined in /etc/rc.config).
+return=$rc_done
 
 case $1 in
-'start')
-	do_start
-	;;
-'stop')
-	do_stop
-	;;
-'restart')
-	do_stop
-	sleep 2 #wait some time...
-	do_start
-	;;
-'start_msg')
-	$ECHO "Starting HylaFAX Servers."
+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 -s $SNPPPORT \
+			||  return=$rc_failed
+		echo -e "$return"
+	fi
 	;;
-'stop_msg')
-	$ECHO "Stopping HylaFAX Servers."
+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: hylafax {start|stop|restart|start_msg|stop_msg}"
+	echo "Usage: /etc/init.d/hylafax {start|stop|restart|reload|status}"
 	;;
 esac
+
+rc_exit
+
