#!/bin/bash
#
# This version of /sbin/hotplug should work on most GNU/Linux systems
# using Linux 2.2.18+ or 2.4.* kernels.  On 2.2.*, only USB has such
# hotplugging support; on 2.4.*, so do PCI/Cardbus and network interfaces.
#
# The kernel HOTPLUG configuration option needs to be enabled, and KMOD
# will normally be enabled so that kernels needn't statically link every
# known driver.
#
#
# HISTORY:
#
# 26-Feb-2001	Cleanup (Gioele Barabucci)
# 14-Feb-2001	Better diagnostics: logging, agent list (contributors)
# 04-Jan-2001	First "New" version, which only delegates to
#		specialized hotplug agents.
#

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

#
# Only one required argument:  event type type being dispatched.
# Examples:  usb, pci, isapnp, net, ieee1394, printer, disk,
# parport, ... 
#
if test $# -lt 1 -o "$1" = "-h" -o "$1" = "--help" -o "$1" = "help"; then
	if test -t; then
		echo "Usage: $0 AgentName [AgentArguments]"

		AGENTS=""
		for AGENT in /etc/hotplug/*.agent ; do
			TYPE=`basename $AGENT | sed s/.agent//`
			if [ -x $AGENT ]; then
				AGENTS="$AGENTS $TYPE"
			else
				AGENTS="$AGENTS ($TYPE)"
			fi
		done
		echo "AgentName values on this system: $AGENTS" 
		echo "Most agents also require particular environment parameters."
	else
		msg "Illegal usage $*"
	fi
	exit 1
fi

agent="/etc/hotplug/$1.agent"
if test -x "$agent"; then
	shift

	exec "$agent" $@

	msg "Could not exec $agent ."
	exit 1
fi

msg "No runnable $1 policy agent is installed."
exit 1
