#! /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

# 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 test -d "/etc/rc.d/rc$runlevel.d" ; then
	#run K scripts first
	for i in /etc/rc.d/rc$runlevel.d/K*
	do
		#if there are no K scripts then don't print an error
		if [ "$i" = "/etc/rc.d/rc$runlevel.d/K*" ]; then
	        	break
	        fi
	                                        	
		#[ ! -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
		if test $i = "/etc/rc.d/rc$runlevel.d/S*"; then break; fi
		#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!!!!"
fi
exit 0
