#! /bin/sh
# /etc/init.d/modules: loads the appropriate modules in `boot'.

PATH="/sbin:/bin:/usr/sbin:/usr/bin"

# See if we have any modules.
[ -d /lib/modules/`uname -r` ] || exit 0

# Create a generic link to the modules for the current kernel
#
# You can have generic symbolic links in /lib/modules/boot
# if you create links to: "../current/subsystem/module.o"
#
ln -snf /lib/modules/`uname -r` /lib/modules/current
if [ \! -r /lib/modules/current/modules.dep ]
then
	echo "Creating module dependencies"
        depmod -a
fi

#
# If you want to re-calculate the dependencies everytime you boot
# enable the following code:
#
#echo -n "Calculating module dependencies... "
#depmod -a
#echo "done."

startkerneld=0;
# Loop over every line in /etc/modules.
echo -n 'Loading modules: '
(cat /etc/modules; echo) | # make sure there is a LF at the end
while read module args
do
	case "$module" in
		auto)	[ ${startkerneld} -eq 0 -a -x /sbin/kerneld ] && \
			echo && /etc/init.d/kerneld start && startkerneld=1;
			continue ;;
		\#*|"") continue ;;
	esac
	echo -n "$module "
	modprobe $module $args
done

echo

#
# Just in case a sysadmin prefers generic symbolic links in
# /lib/modules/boot for boot time modules we will load these modules
#
if find /lib/modules/boot -type f -o type l > /dev/null 2>&1
then
	modprobe -a -t boot \*
fi
