#! /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}"

	if test ! -x "/etc/hotplug/$subsys_managing.agent"; then
		echo "${rcmsgerr}The agent for the hotplug managing subsystem ($subsys_managing) cannot be ran!${rcmsgz}"
		echo "This means that the system cannot determine which hardware drivers to load."
		echo "If you have been messing with the hotplug scripts then you should make the"
		echo "following script functional again, otherwise you will need to manually load"
		echo "and set up all the appropriate drivers (a la Slackware):"
		echo
		echo "/etc/hotplug/$subsys_managing.agent"
		echo
		exit 1
	fi
	
	ACTION=start "/etc/hotplug/$subsys_managing.agent"
	touch /var/lock/subsys/hotplug
	;;

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

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

	if test ! -x "/etc/hotplug/$subsys_managing.agent"; then
		echo "${rcmsgerr}The agent for the hotplug managing subsystem ($subsys_managing) cannot be ran!${rcmsgz}"
		echo "This means that the system cannot determine which hardware drivers to unload."
		echo "If you have been messing with the hotplug scripts then you should make the"
		echo "following script functional again, otherwise you will need to manually unload"
		echo "all the appropriate drivers (a la Slackware):"
		echo
		echo "/etc/hotplug/$subsys_managing.agent"
		echo
		exit 1
	fi

	ACTION=stop "/etc/hotplug/$subsys_managing.agent"
	rm -f /var/lock/subsys/hotplug
	;;

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

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