#! /bin/sh
#
# load-modules: load all the modules we can find at bootup time.
#
DRIVERS=
PATH=/sbin:/bin:/usr/sbin:/usr/bin

# if we have a nic configuration (/etc/rc.d/nic.cfg is probably not the
# best place to put this, but it will do for now), try loading it.  If
# a configuration exists, but is empty, this is how the system tells us
# that we shouldn't be loading ethernet drivers.)
#
if [ -s /etc/rc.d/nic.cfg ]; then
    echo "Installing ethernet device drivers"
    err=0
    while read driver; do
	if modprobe $driver; then
	    echo "... installed $driver"
	    DRIVERS="$DRIVERS $driver"
	else
	    err=`expr 1 + $err`
	fi
    done < /etc/rc.d/nic.cfg
    [ $err -gt 0 ] || exit 0
    rm -f /etc/rc.d/nic.cfg
fi

# If we get here, either there's no nic.cfg or something went wrong
# when trying to install the existing drivers.  So we will do a reprobe
# (in the probe order in drivers/net/Space.c) of all the devices we
# support.

ISAPROBE="smc-ultra wd 3c503 ne eth16i 3c509 eexpress depca lance"
ISAPROBE="$ISAPROBE ewrk3 3c501 wavelan 3c507 3c505"
PCIPROBE="3c59x tulip eepro eepro100 tlan via-rhone yellowfin epic100"

echo -n "Looking for ethernet hardware:"

found=0
for dev in $ISAPROBE $PCIPROBE; do
    if modprobe $dev 2>/dev/null; then
	echo -n " $dev"
	DEVICES="$DEVICES $dev"
	found=`expr 1 + $found`
    fi
done
if [ $found -eq 0 ]; then
    echo " none"
else
    echo
fi

# when we're all done, write what we found back into the configuration
# file.
if [ "$DEVICES" ]; then
    for dev in $DEVICES;do
	echo $dev
    done > /etc/rc.d/nic.cfg
fi

exit 0
