#!/bin/sh
# /etc/init.d/mythbuntu-diskless-client: set up various things on mythbuntu-diskless clients

# technically, we require the root system to be mounted before this scripted is
# started
# practically, it doesn't matter because init is never started if / is not mounted

### BEGIN INIT INFO
# Provides:          mythbuntu-diskless-client
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mythbuntu-diskless-client setup
# Description:       set up various things on mythbuntu-diskless clients, eg xorg.conf
### END INIT INFO

# borrowed from ltsp-client-core
test -f /etc/ltsp_chroot || exit 0

PATH=/bin:/usr/bin:/sbin:/usr/sbin

case "$1" in start|restart|force-reload)


    # this is really -diskless-specific:
    # if the overlay directory has an xorg.conf, we can assume that it's valid
    # we used to check for /etc/X11/xorg.conf, but that does not work in case
    # the squashfs already contains one (which might be invalid)
    if [ ! -e "/cow/etc/X11/xorg.conf" ]; then
        # run ltsp configure script
        /usr/lib/ltsp/configure-x.sh
    fi
    
    # nbd-client shouldn't be killed by /etc/init.d/sendsigs
    mkdir -p /var/run/sendsigs.omit.d/
    # just ignore any nbd-client instances in sendsigs 
    pidof nbd-client > /var/run/sendsigs.omit.d/nbd-client


;;

status|stop)
    # do nothing
;;

*)
    echo "$0: invalid arguments. Use  'start', 'restart', 'force-reload', 'stop' or 'status'."
    echo "$0: 'stop' and 'status' don't do anything and are just there for compatibility reasons."

;;

esac
