#!/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 AGENT [ARGS]"

		AGENTS=""
		for AGENT in /etc/hotplug/*.agent ; do
			test -x $AGENT && AGENTS="$AGENTS `basename $AGENT .agent`"
		done
		echo "Agents 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
	msg "No runnable $1 policy agent is installed."
	exit 1
fi

shift
exec "$AGENT" $@

msg "Could not exec $AGENT ."
exit 1
