#! /bin/sh
#
# Author:	Matt Zimmerman <mdz@ubuntu.com>
#
### BEGIN INIT INFO
# Provides:          ltsp-client ltsp-client-core ltsp-client-setup
# Required-Start:    $remote_fs $network $syslog
# Should-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 6
# Short-Description: Script for LTSP client initialization
# Description:
### END INIT INFO

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 an LTSP boot was not requested
grep -qs "init=/sbin/init-ltsp" /proc/cmdline || exit 0

# handle localization settings
if [ -r /etc/default/locale ]; then
  . /etc/default/locale
  export LANG LANGUAGE
elif [ -r /etc/environment ]; then
  . /etc/environment
  export LANG LANGUAGE
fi

. /lib/lsb/init-functions
. /usr/share/ltsp/ltsp-init-common

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

        if [ -f "/etc/ltsp/getltscfg-cluster.conf" ]; then
            # Tell the control center that we are booting and get lts.conf
            eval $(getltscfg-cluster -a -l boot) || true
        fi

        if [ -x /bin/plymouth ]; then
            /bin/plymouth quit --retain-splash || true
        fi

        start_printers || true
        start_screen_sessions || true
        start_sound || true

        log_action_end_msg 0
	;;
  stop)
	;;
  restart|force-reload)
    echo "$NAME does not support restarting, reboot your client instead." >&2
    exit 1
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
