#!/bin/sh

# loads modules for network cards and nfs

# copyright 2004 vagrant@freegeek.org, distributed under the terms of the
# GNU General Public License version 2 or any later version.

if [ "true" = "$discover_probe" ] && [ -f /proc/bus/pci/devices ] && [ -r /usr/share/discover/pci.lst ]; then
  echo "Scanning for PCI network cards..."
  for pci_id in $(cut -f 2 /proc/bus/pci/devices) ; do
    # FIXME: support pci-26.lst and /etc/lessdisks/discover1.custom
    driver=$(grep $pci_id /usr/share/discover/pci.lst | head -n 1 | grep ethernet | cut -f 4)
    if [ -n "$driver" ]; then
      echo "Found ethernet card for pci id $pci_id : $driver"
      detected_modules="$detected_modules $driver"
    fi
  done
  # also probe for modules discover knows about"
  nic_modules="$nic_modules $discover_modules"
fi

# load default modules.
io_ports="0x300 0x280"

for module in $net_modules $NIC $detected_modules $nic_modules ; do
  if [ "true" = "$first_ethernet_only" ] && [ -n "$(ifconfig eth0 2> /dev/null)" ]; then
    break
  fi
  for io_port in $io_ports ; do
    case $module in
      # support for ne2000 card in qemu, maybe others
      ne|eexpress) module="$module io=$io_port" 
    esac
  done
  modprobe -q -k $module > /dev/null 2>&1
done
