#! /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.
#
# Version:	@(#) /etc/rc 1.01 26-Oct-1993
#
# Author:	Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#

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

  # Now find out what the current and what the previous runlevel are.
  argv1="$1"
  set `/sbin/runlevel`
  runlevel=$2
  previous=$1
  export runlevel previous

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

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

			# See if there is a start script.
			prefix1=/etc/rc$runlevel.d/K
			prefix2=/etc/rc$runlevel.d/S
			start=${i#$prefix1}
			[ -f $prefix2$start ] && continue

			# No startup script so kill it.
			[ -f $i ] && $i stop
		done
	fi
	# Now run the START scripts for this runlevel.
	for i in /etc/rc$runlevel.d/S*
	do
		[ -f $i ] && $i start
	done
  fi

