#! /bin/sh
#
# Author:   Matt Zimmerman <mdz@ubuntu.com>
#
### BEGIN INIT INFO
# Provides:          ltsp-client-setup
# Required-Start:    mountdevsubfs 
# X-Start-Before:    mountall
# Required-Stop:     
# Default-Start:     S
# Default-Stop:      
# 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 setup"
NAME=ltsp-client-setup
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if ltsp_chroot file is not present
test -f /etc/ltsp_chroot || exit 0

test -f /etc/default/ltsp-client-setup && . /etc/default/ltsp-client-setup

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

case "$1" in
    start)
        log_begin_msg "Setting up LTSP client..."
        which usplash_write >/dev/null 2>/dev/null && \
            usplash_write "TIMEOUT 120" || true
        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 refresh) || true
        fi
        load_modules || true
        configure_resolver || true
        set_time || true
        configure_console || true
        configure_swap || true
        configure_syslog || true
        configure_fstab || true
        configure_home || true
        configure_cron || true
        run_rcfiles || true
        configure_serial_mouse || true
        configure_localdev || true
        configure_printer || true
        configure_scanner || true
        nbd_sendsigs_protection || true
        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|force-reload}" >&2
        exit 1
        ;;
esac

exit 0
