#!/bin/sh
### BEGIN INIT INFO
# Provides:          ltsp_set_runlevel
# Required-Start:    $remote_fs $all
# Required-Stop:     $remote_fs $all
# Should-Start:      console-screen console-setup xfree86-common
# Default-Start:     S
# Default-Stop:      
# Short-Description: Select runlevel for LTSP client at boot time
# Description:       Based on current IP address, select runlevel
#                    for the LTSP client at boot time.  This allow it
#                    to switch dynamically between thin client and
#                    diskless workstation profile.
### END INIT INFO

case "$1" in
    start) ;;
    *) exit 0 ;;
esac

# Skip automatic runlevel selection if runlevel is specified on the
# kernel command line.
for arg in $(cat /proc/cmdline) ; do
    case "$arg" in
	0|1|2|3|4|5|6)
	    exit 0
	    ;;
    esac
done

IP_ETH=$(/sbin/ifconfig eth0 | sed -ne 's/ *inet addr:\([0-9.]*\) .*/\1/p')

case "$IP_ETH" in
    10.*)
	echo "Detected 10.* network.  Selecting diskless workstation LTSP setup."
	telinit 3 ;;
    192.*)
	echo "Detected 192.* network.  Selecting thin client LTSP setup."
	telinit 4 ;;
esac

exit 0
