#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          kmod
# Required-Start:    
# Required-Stop:     
# Should-Start:      checkroot
# Should-Stop:
# Default-Start:     S
# Default-Stop:
# Short-Description: Load the modules listed in /etc/modules.
# Description:       Load the modules listed in /etc/modules.
### END INIT INFO

# Silently exit if the kernel does not support modules.
[ -f /proc/modules ] || exit 0
[ -x /sbin/modprobe  ] || exit 0

[ -f /etc/default/rcS ] && . /etc/default/rcS
. /etc/init.d/functions

PATH='/bin:/usr/bin:/sbin:/usr/sbin'

case "$1" in
  start)
	# Exit if there's no modules file or there are no
	# valid entries
	[ -r /etc/modules ] &&
	    egrep -qv '^($|#)' /etc/modules ||
	    exit 0

	echo "Loading modules:"
	depmod -a
	# Only try to load modules if the user has actually given us
	# some modules to load.
	while read module args; do

	    # Ignore comments and blank lines.
	    case "$module" in
			""|"#"*) continue ;;
	    esac

	    # Attempt to load the module, making
	    # sure to pass any arguments provided.
	    modprobe ${module} ${args} >/dev/null

	    # Print the module name if successful,
	    # otherwise take note.
	    if [ $? -eq 0 ]; then
			successmod="${successmod} ${module}"
	    else
			failedmod="${failedmod} ${module}"
	    fi
	done < /etc/modules

	echo ""
	# Print a message about successfully loaded
	# modules on the correct line.
	success
	echo "${successmod} loaded"

	# Print a failure message with a list of any
	# modules that may have failed to load.
	if [ -n "${failedmod}" ]; then
	    failure
	    echo "Failed to load modules:${failedmod}"
	fi
	;;

  stop|restart|reload|force-reload)
	warning 
	echo "Action '$1' is meaningless for this init script"
	exit 0
	;;

  *)
	echo "Usage: $0 start"
	exit 1
	;;
esac


