#!/bin/sh
#
# Start kerneld (on-demand loading of modules)
# (see /usr/share/doc/modutils)

KDOPT=""

test -f /proc/sys/kernel/modprobe && exit 0
test -f /sbin/kerneld || exit 0

#
# See if we have any modules.
#
cd /lib/modules/`uname -r` > /dev/null 2>&1 || exit 0

case "$1" in
  start)
#
#	are /proc and /usr/sbin mounted ?
#
	if `cd /proc/sys > /dev/null 2>&1` && `cd /usr/sbin > /dev/null 2>&1`
	then
#
#		Check if noauto is set
#
		grep "^[ ]*noauto" /etc/modules 2>&1 > /dev/null && exit 0
	        start-stop-daemon --start --quiet --exec /sbin/kerneld -- "${KDOPT}"
	else
		/sbin/kerneld ${KDOPT}
	fi
	;;
  stop)
        start-stop-daemon --stop --quiet --oknodo --exec /sbin/kerneld -- "${KDOPT}"
	;;
  restart)
  		$0 stop
		$0 start
	;;
  reload)
  		start-stop-daemon --stop --signal 1 --q	quiet --exec /sbin/kerneld
	;;
  force-reload)
  		$0 reload
	;;
  *)
	echo "Usage: /etc/init.d/kerneld {start|stop|restart|reload|force-reload}"
	exit 1
	;;
esac

exit 0
