#! /bin/sh
# /etc/init.d/bl
#
# Adaptated by Piotr Roszatycki <dexter@debian.org>

# additional options for bl
OPTS="-b"

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/bl
NAME=bl
DESC="blinkenlights"

test -f $DAEMON || exit 0
set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	# start and stop bl for each tty
	# this is ugly hack - after that bl blinks for all ttys
	start-stop-daemon --start --quiet --exec $DAEMON -- tty1
	start-stop-daemon --stop --quiet --oknodo --exec $DAEMON -- tty1
	for i in 2 3 4 5 6 7 8 9 10 11 12; do
	    start-stop-daemon --start --quiet --pidfile /dev/null \
		--exec $DAEMON -- tty$i
	    start-stop-daemon --stop --quiet --oknodo --exec $DAEMON -- tty$i
	done
	sleep 1
	# start bl again for tty1
	nice -n 20 \
	     start-stop-daemon --start --quiet --exec $DAEMON -- $OPTS tty1
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --oknodo --exec $DAEMON -- tty1
	sleep 1
	echo "$NAME."
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --quiet --oknodo --exec $DAEMON -- tty1
	sleep 1
	nice -n 20 \
	     start-stop-daemon --start --quiet --exec $DAEMON -- $OPTS tty1
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
