#! /bin/sh
#
# /etc/rcS	
# Technologic Systems 		2.28.02
# This script will descend into the rcN.d directory of the specified
# runlevel and execute all K scripts (passing them 'stop' argument)
# and then execute all S scripts (passing them the 'start' agument)
#

# Ignore CTRL+C
trap ":" INT QUIT TSTP

PATH=/sbin:/bin:/usr/sbin:/usr/bin
umask 022
export PATH 

runlevel=$RUNLEVEL

[ "$1" != "" ] && runlevel=$1

# You'll notice we don't do that previous runlevel thing
# that other distros do


# Check that there is indeed an rcN.d directory to descend into
if [ -d "/etc/rc.d/rc$runlevel.d" ]; then
	#run K scripts first
	for i in /etc/rc.d/rc$runlevel.d/K*
	do
		[ ! -x "$i" ] && continue
		#we make the assumption that all K scripts in rcN.d
		#need the stop argument
		$i stop
	done
	#run S scripts 
	for i in /etc/rc.d/rc$runlevel.d/S*
	do
		[ ! -x "$i" ] && continue
		#we make the assumption that all S  scripts in rcN.d
		#need the start argument
		$i start
	done
else

	echo "ERROR!!! No /etc/rc.d/rc$runlevel.d directory found!!!!"
	echo "ERROR!!! No /etc/rc.d/rc$runlevel.d directory found!!!!" >&2
fi
echo "/etc/rc.d/rcS $1 finished running..exiting with exit 0"
exit 0
