#! /bin/sh
### BEGIN INIT INFO
# Provides:          cups-browsed
# Required-Start:    $syslog $remote_fs $network $named $time
# Required-Stop:     $syslog $remote_fs $network $named $time
# Should-Start:      avahi-daemon
# Should-Stop:       avahi-daemon
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: cups-browsed - Make remote CUPS printers available locally
# Description: This daemon browses Bonjour broadcasts of shared remote CUPS
#              printers and makes these printers available locally by creating
#              local CUPS queues pointing to the remote queues. This replaces
#              the CUPS browsing which was dropped in CUPS 1.6.1. For the end
#              the behavior is the same as with the old CUPS broadcasting/
#              browsing, but in the background the standard method for network
#              service announcement and discovery, Bonjour, is used.
### END INIT INFO

DAEMON=/usr/sbin/cups-browsed
NAME=cups-browsed
PIDFILE=/var/run/cups/$NAME.pid
DESC="CUPS Bonjour daemon"

unset TMPDIR

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

SSD_OPTIONS="--pidfile $PIDFILE --make-pidfile"

case "$1" in
  start)
	gprintf "Starting $NAME"
    mkdir -p `dirname "$PIDFILE"`
	start-stop-daemon --start --oknodo --background $SSD_OPTIONS --exec $DAEMON
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ]
	;;
  stop)
        gprintf "Stopping $NAME service: "
        killproc $NAME
        RETVAL=$?

        echo
        [ $RETVAL -eq 0 ] && rm -f $PIDFILE
        ;;
  restart)
        $0 stop
        $0 start
	RETVAL=$?
        ;;
  status)
        status cups-browsed
	RETVAL=$?
        ;;
  *)
	gprintf "Usage: cups {start|stop|restart|status}\n"
	exit 1
	;;
esac

exit $RETVAL
