#!/bin/sh
#
# rc            This file is responsible for starting/stopping
#               services when the runlevel changes. It is also
#               responsible for the very first setup of basic
#               things, such as setting the hostname.
#
# Original Author:       
#               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#

# Source function library.
. /etc/rc.d/init.d/functions

# enter normal mode
argv1="$1"

set `/sbin/runlevel`
runlevel=$2
previous=$1
export runlevel previous

# See if we want to be in user confirmation mode
if [ "$previous" = "N" ]; then
    if grep -i confirm /proc/cmdline >/dev/null ; then
      CONFIRM=yes
    else
      CONFIRM=
    fi
fi

# Get first argument. Set new runlevel to this argument.
[ "$1" != "" ] && runlevel="$argv1"

# Tell linuxconf what runlevel we are in
[ -d /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir

# Is there an rc directory for this new runlevel?
if [ -d /etc/rc.d/rc$runlevel.d ]; then
	# First, run the KILL scripts.
	for i in /etc/rc.d/rc$runlevel.d/K*; do
		# Check if the script is there.
		[ ! -f $i ] && continue

			$i stop
	done

	# Now run the START scripts.
	for i in /etc/rc.d/rc$runlevel.d/S*; do
		# Check if the script is there.
		[ ! -f $i ] && continue

			$i start
	done
fi
