#! /bin/sh
#
# Linux hotplug framework (hardware management)
#

# RC script configuration
test -e /etc/init.d/rc.conf && . /etc/init.d/rc.conf

test -f /proc/sys/kernel/hotplug || exit 5
hotplug="`head -n 1 /proc/sys/kernel/hotplug`"
test -x "$hotplug" -a -d /etc/hotplug || exit 5

# Global hotplug configuration
test -e /etc/hotplug.conf && . /etc/hotplug.conf

case "$1" in

	(start)
	echo "${rcmsg}Loading hardware drivers...${rcmsgz}"

	for agent in $subsys_managing; do
		if test -x "/etc/hotplug/$agent.agent"; then
			ACTION=start "/etc/hotplug/$agent.agent"
		else
			echo "${rcmsgerr}Cannot find hotplug agent: $agent${rcmsgz}"
		fi
	done

	touch /var/lock/subsys/hotplug
	;;

	(stop)
	test "$RC_FAST_SHUTDOWN" = "yes" && exit 0

	echo "${rcmsg}Unloading hardware drivers...${rcmsgz}"

	for agent in $subsys_managing; do
		if test -x "/etc/hotplug/$agent.agent"; then
			ACTION=stop "/etc/hotplug/$agent.agent"
		else
			echo "${rcmsgerr}Cannot find hotplug agent: $agent${rcmsgz}"
		fi
	done

	rm -f /var/lock/subsys/hotplug
	;;

	(restart) $0 stop && $0 start ;;

	(*) echo "Usage: $0 {start|stop|restart}">/dev/stderr; exit 1;;
esac
