#!/sbin/runscript
# Copyright 1999-2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/modules,v 1.17 2002/12/01 17:45:18 azarah Exp $


depend() {
	need checkroot hostname
}

start() {
	# Should not fail if kernel do not have module
	# support compiled in ...
	[ -f /proc/modules ] || return 0
	
	# Here we should fail, as a modular kernel do need
	# depmod command ...
	if [ ! -x /sbin/depmod ]
	then
		eerror "ERROR:  system is missing /sbin/depmod !"
		return 1
	fi
	
	ebegin "Calculating module dependencies"
	/sbin/modules-update &>/dev/null
	eend $? "Failed to calculate dependencies"

	# Loop over every line in /etc/modules.autoload.
	(cat /etc/modules.autoload; echo) | # make sure there is a LF at the end
	while read module args
	do
		case "${module}" in
			\#*|"") continue ;;
		esac
		ebegin "  Loading module ${module}"
		modprobe ${module} ${args} &>/dev/null
		eend $? "  Failed to load ${module}"
	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 [ -n "$(modprobe -l -t boot)" ]
	then
		modprobe -a -t boot \*  &>/dev/null
	fi
}


# vim:ts=4
