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

. /lib/lsb/init-functions
. /etc/default/rcS

PATH="/sbin:/bin"

[ -f /proc/ksyms ] || exit 0
[ -e /sbin/depmod ] || exit 0

if touch /lib/modules/$(uname -r)/modules.dep 2>/dev/null; then
	log_begin_msg "Calculating module dependencies..."
	if depmod -a -q; then
		log_end_msg 0
	else
		log_end_msg 1
	fi
else
	log_failure_msg "Not calculating module dependencies: /lib/modules/$(uname -r) is read only."
fi

# Loop over every line in /etc/modules.
log_begin_msg 'Loading modules...'
(cat /etc/modules; echo) | # make sure there is a LF at the end
while read module args
do
	case "$module" in
		\#*|"") continue ;;
	esac
	if [ "$VERBOSE" != no ]; then
		log_begin_msg "Trying module $module..."
		if modprobe $module $args >/dev/null 2>&1; then
			log_end_msg 0
		else
			log_end_msg 1 || true
		fi
	else
		modprobe $module $args >/dev/null 2>&1		
	fi
done
log_end_msg 0

#
# Just in case a sysadmin prefers generic symbolic links in
# /lib/modules/boot for boot time modules we will load these modules
#
if [ -n "`modprobe -l -t boot`" ]
then
        modprobe -a -t boot \*
fi

exit 0

