#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../sysfiles/etc_rc.d_rc.txt
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

#
# ROCK Linux: /etc/rc.d/rc
#
# This script does the switching between runlevels.
#

{
export PATH=/bin:/sbin:/usr/bin:/usr/sbin

echo "** running rc script **"
echo "RC: Previous runlevel: $PREVLEVEL, new runlevel: $RUNLEVEL."

curdir=/etc/rc.d/rc$RUNLEVEL.d
prevdir=/etc/rc.d/rc$PREVLEVEL.d

#
# run the KILL scripts of the previous runlevel (if needed)
#
if ! [ $PREVLEVEL = S -o $PREVLEVEL = N ]
then
	echo "RC: Leave runlevel $PREVLEVEL ..."
	for i in $prevdir/K*; do
		if ! test -x "$i" ; then
			echo "Warning: $i is not executable: skipped."
			continue
		fi
		x="`echo "$i" | sed "s,$prevdir/K..,$curdir/S??,"`"
		[ "`echo $x`" = "$x" ] || continue
		/sbin/rc --nobtee $i stop
	done
fi

echo "RC: Enter runlevel $RUNLEVEL ..."

if [ $RUNLEVEL != 0 -a $RUNLEVEL != 6 -a $RUNLEVEL != S ]
then
	#
	# run the START scripts of the current (new) runlevel
	#
	for i in $curdir/S*; do
		if ! test -x "$i" ; then
			echo "Warning: $i is not executable: skipped."
			continue
		fi

		x="`echo "$i" | sed "s,$curdir/S..,$prevdir/K??,"`"
		[ "`echo $x`" = "$x" ] || continue
		/sbin/rc --nobtee $i start
	done
fi

echo "RC: The system is now in runlevel $RUNLEVEL."

# write EOT mark for btee
echo -ne '\004'

} 2>&1 | /sbin/btee a /var/log/init.msg

exit 0