#! /bin/sh
# Copyright (c) 1996 S.u.S.E. Gmbh Fuerth, Germany.  All rights reserved.
#
# Author: Florian La Roche <florian@suse.de>, 1996
#	  Werner Fink <werner@suse.de>, 1996
#
# This file is responsible for starting/stopping services
# when the runlevel changes. If the action for a particular
# feature in the new run-level is the same as the action in
# the previous run-level, this script will neither start nor
# stop that feature.
#

. /etc/rc.config

# ignore CTRL-C only in this shell, so we can interrupt subprocesses
trap ":" INT QUIT TSTP

# set onlcr to avoid staircase effect
stty onlcr 0>&1

echo "$0: Previous runlevel: $PREVLEVEL, current runlevel: $RUNLEVEL."

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

if test "$PREVLEVEL" != N; then
	#
	# run the KILL scripts of the previous runlevel
	#
	rev=
	for i in $prevdir/K*; do
	   rev="$i $rev"
	done
	for i in $rev; do
	   test -x "$i" || continue

	   # don't run the kill script, if the new runlevel has a start script
	   start=${i##*/K[0-9][0-9]}
	   test -f $curdir/S*$start && continue

	   $i stop
	done
fi
#
# run the START scripts of the current (new) runlevel
#
for i in $curdir/S*; do
    test -x "$i" || continue

    # don't run start script, if previous runlevel had a kill script
    if test "$PREVLEVEL" != N; then
	start=${i##*/S[0-9][0-9]}
	test -f $prevdir/K*$start && continue
    fi

    $i start
done

exit 0
