#!/bin/bash
#
# This version of /sbin/hotplug should works 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:
#
# 04-Jan-2001	First "New" version, which only delegates to
#		specialized hotplug agents.
#

cd /etc/hotplug
. hotplug.functions

# DEBUG=yes export DEBUG

if [ "$DEBUG" != "" ]; then
    mesg "arguments ($*) env (`env`)"
fi

#
# Only one required argument:  event type type being dispatched.
# Examples:  usb, pci, isapnp, net, ieee1394, printer, disk, ... 
#
if [ $# -lt 1 -o $1 = help -o $1 = '--help' ]; then
    if [ -t ]; then
	echo "Usage: $0 {usb,pci,net,...} ..."
	echo "Environment parameters are also type-specific."
# FIXME: list non-builtin agents (/etc/hotplug/*.agent)
    else
	mesg "illegal usage $*"
    fi
    exit 1
fi

AGENT=/etc/hotplug/$1.agent

#
# Delegate event handling:
#   /sbin/hotplug FOO ..args.. ==> /etc/hotplug/FOO.agent ..args..
#
if [ -x $AGENT ]; then
    shift
    exec $AGENT "$@"
    mesg "couldn't exec $AGENT"
    exit 1
fi

mesg "no runnable $AGENT is installed"
exit 1
