#!/bin/sh
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL
PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/sbin

# Load the network device modules defined in /etc/modules in network initrd
# This code is from Debian Sarge /etc/init.d/modutils
# Loop over every line in /etc/modules.
echo "Loading the module from /etc/modules if assigned and exists..."
(cat /etc/modules; echo) | # make sure there is a LF at the end
while read module args; do
  case "$module" in
  	\#*|"") continue ;;
  esac
  echo -n "$module "
  modprobe $module $args 2>/dev/null
done

# Detect and load the network devices
NIC_MOD="$(scan_pci)"
[ -n "$NIC_MOD" ] && echo "The detected modules for hardware: $NIC_MOD. Try to load them..."
for mod in $NIC_MOD; do
  modprobe $mod 2>/dev/null
done
netdevices="$(get-nic-devs)"
if [ -z "$netdevices" ]; then
  kernel_ver=`uname -r`
  echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  echo "The driver of network card is NOT found!"
  echo "Is this kernel $kernel_ver too old so it does not support this network card ?"
  echo "Without network card driver, we can NOT go on!"
  echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  echo "Now enter shell to debug..."
  /bin/sh
fi

# nfs.o depends on sunrpc, lockd
modprobe nfs

# Always require af_packet for udhcpc if af_packet is not builtin.
# Normally, for RedHat-like, it's builtin. For Debian-like, it's a module.
# Anyway, we just test before do it.
if modprobe -n af_packet 2>/dev/null; then
  modprobe af_packet
fi
