#!/bin/sh -e
#
# isapnp.rc	synthesizes isapnp hotplug events at boot time
#		it requires a 2.6 kernel with CONFIG_ISAPNP defined
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#	
#  Copyright (C) 2004 Simone Gotti <simone.gotti@email.it>
#  Copyright (C) 2004 Marco d'Itri <md@linux.it>
#

# only 2.6 kernels are supported
[ -d /sys/bus/pnp/devices/ ] || exit 0

cd /etc/hotplug
. ./hotplug.functions

isapnp_boot_events()
{
    if [ "$(echo /sys/bus/pnp/devices/*/id)" = "/sys/bus/pnp/devices/*/id" ];
    then
	return 0
    fi

    cat /sys/bus/pnp/devices/*/id \
    | while read PNPID; do
	# get the name of the module which should be loaded
	MODULE=$(modprobe --show-depends -q pnp:d$PNPID \
		| sed -e '$!d;s/.*\/\(.*\)\.ko .*/\1/')

	case "$MODULE" in
	"")			# continue if there is no alias available
	    continue
	    ;;
	install*)		# skip the blacklist check if install is used
	    MODULE="pnp:d$PNPID"
	    ;;
	*)			# ignore blacklisted devices
	    if is_blacklisted $MODULE; then
		mesg "     $MODULE: blacklisted"
		continue
	    fi
	    ;;
	esac

	# see do_pnp_entry() in /usr/src/linux/scripts/file2alias.c
	if $MODPROBE -q $MODULE; then
	    mesg "     $MODULE: loaded sucessfully"
	else
	    mesg "     $MODULE: can't be loaded"
	fi
    done
}

# See how we were called.
case "$1" in
    start|restart)
	isapnp_boot_events
	;;
    stop)
	# echo "isapnp stop -- ignored"
	;;
    status)
	# echo "isapnp status -- ignored"
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
esac

