#! /bin/sh
#
# ltsp-client	Script for LTSP client initialization
#
# Author:	Matt Zimmerman <mdz@ubuntu.com>
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="LTSP client"
NAME=ltsp-client
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

. /lib/lsb/init-functions
. /usr/lib/ltsp/ltsp_functions
. /usr/lib/ltsp/ltsp_config

case "$1" in
  start)
        log_begin_msg "Starting LTSP client..."

        for screen in $(env | awk -F= '$1 ~ /^SCREEN_/ { print $1 }'); do
            num=${screen##SCREEN_}
            start-stop-daemon --start -b --exec /usr/lib/ltsp/screen_session -- "$num"
        done
        

        log_end_msg 0
	;;
  stop)
#	echo -n "Stopping $DESC: $NAME"
#	d_stop
#	echo "."
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	echo -n "Restarting $DESC: $NAME"
	d_stop
	sleep 1
	d_start
	echo "."
	;;
  *)
	# echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
