#!/bin/ash

# <lessdisks-path>/etc/init.d/switchrunlevel
# last script to run in runlevel 2 
# determines appropriate runlevel from system-specific config file..

if [ -r /rw/etc/hostname ]
then
	hostname=`cat /rw/etc/hostname`
else
	echo "WARNING: /rw/etc/hostname not found... something is amiss"
fi

if [ -r /etc/lessdisks/terminals/$hostname ]
then
	. /etc/lessdisks/terminals/$hostname
else
	echo "WARNING: /etc/lessdisks/terminals/$hostname not found..."
fi

if [ -z "$runlevel" ]
then
	echo "runlevel not set, assuming runlevel 2"
	runlevel=2
fi

case in $runlevel
	2) exit 0 ;;
	3|4|5) echo "switching to runlevel $runlevel"
		telinit $runlevel
		exit 0 ;;
	*) echo "WARNING: runlevel set to $runlevel"
		echo "change runlevel value in /etc/lessdisks/terminals/$hostname to 2,3,4 or 5"
		exit 1 ;;
esac