| 1 |
#!/sbin/runscript
|
| 2 |
# Copyright 1999-2005 Gentoo Foundation
|
| 3 |
# Distributed under the terms of the GNU General Public License v2
|
| 4 |
|
| 5 |
depend() {
|
| 6 |
need checkroot hostname
|
| 7 |
use isapnp
|
| 8 |
}
|
| 9 |
|
| 10 |
load_modules() {
|
| 11 |
local x=
|
| 12 |
local i=0
|
| 13 |
local retval=0
|
| 14 |
local modules=
|
| 15 |
local modargs=
|
| 16 |
local modcount=0
|
| 17 |
local config="$1"
|
| 18 |
|
| 19 |
[ -z "${config}" ] && return 0
|
| 20 |
[ ! -r "${config}" ] && return 0
|
| 21 |
|
| 22 |
# Loop over every line in $config
|
| 23 |
eval $(awk '
|
| 24 |
BEGIN {
|
| 25 |
COUNT = 0 # Make sure COUNT is set
|
| 26 |
}
|
| 27 |
|
| 28 |
$0 !~ /(^[[:space:]]*(#|$))/ {
|
| 29 |
if (MODULES == "")
|
| 30 |
MODULES = $1
|
| 31 |
else
|
| 32 |
MODULES = MODULES " " $1
|
| 33 |
|
| 34 |
# Not the greatest method to remove $1 from $0, but it works
|
| 35 |
sub(/^[[:space:]]*[^[:space:]]*[[:space:]]*/, "")
|
| 36 |
ARGS[COUNT] = $0
|
| 37 |
COUNT++
|
| 38 |
}
|
| 39 |
|
| 40 |
END {
|
| 41 |
# 'eval' will make sure these are set to proper bash variables
|
| 42 |
print "modcount=" COUNT
|
| 43 |
print "modules=\"" MODULES "\""
|
| 44 |
for (x = 0;x < COUNT;x++)
|
| 45 |
print "modargs[" x "]=\"" ARGS[x] "\""
|
| 46 |
}
|
| 47 |
' "${config}")
|
| 48 |
|
| 49 |
if [ "${modcount}" -gt 0 ]
|
| 50 |
then
|
| 51 |
einfo "Using ${config} as config:"
|
| 52 |
|
| 53 |
for x in ${modules}
|
| 54 |
do
|
| 55 |
ebegin " Loading module ${x}"
|
| 56 |
modprobe -q ${x} ${modargs[${i}]} &>/dev/null
|
| 57 |
retval=$?
|
| 58 |
eend ${retval} " Failed to load ${x}"
|
| 59 |
|
| 60 |
i=$((i+1))
|
| 61 |
[ "${retval}" -eq 0 ] || modcount=$((modcount-1))
|
| 62 |
done
|
| 63 |
|
| 64 |
einfo "Autoloaded ${modcount} module(s)"
|
| 65 |
fi
|
| 66 |
|
| 67 |
return 0
|
| 68 |
}
|
| 69 |
|
| 70 |
start() {
|
| 71 |
local KV=$(uname -r)
|
| 72 |
local KV_MAJOR=$(KV_major "${KV}")
|
| 73 |
local KV_MINOR=$(KV_minor "${KV}")
|
| 74 |
local KV_MICRO=$(KV_micro "${KV}")
|
| 75 |
|
| 76 |
# Should not fail if kernel do not have module
|
| 77 |
# support compiled in ...
|
| 78 |
[ -f /proc/modules ] || return 0
|
| 79 |
|
| 80 |
# Here we should fail, as a modular kernel do need
|
| 81 |
# depmod command ...
|
| 82 |
if [ ! -x /sbin/depmod ]
|
| 83 |
then
|
| 84 |
eerror "ERROR: system is missing /sbin/depmod !"
|
| 85 |
return 1
|
| 86 |
fi
|
| 87 |
|
| 88 |
if [ -z "${CDBOOT}" ] && touch /etc/modules.conf 2> /dev/null
|
| 89 |
then
|
| 90 |
ebegin "Calculating module dependencies"
|
| 91 |
/sbin/modules-update &>/dev/null
|
| 92 |
eend $? "Failed to calculate module dependencies"
|
| 93 |
fi
|
| 94 |
|
| 95 |
local autoload=""
|
| 96 |
if [[ -f /etc/modules.autoload && ! -L /etc/modules.autoload ]]; then
|
| 97 |
autoload=/etc/modules.autoload
|
| 98 |
else
|
| 99 |
local x
|
| 100 |
for x in "${KV}" ${KV_MAJOR}.${KV_MINOR}.${KV_MICRO} ${KV_MAJOR}.${KV_MINOR} ; do
|
| 101 |
if [[ -f /etc/modules.autoload.d/kernel-"${x}" ]] ; then
|
| 102 |
autoload="/etc/modules.autoload.d/kernel-${x}"
|
| 103 |
break
|
| 104 |
fi
|
| 105 |
done
|
| 106 |
fi
|
| 107 |
[[ -n ${autoload} ]] && load_modules "${autoload}"
|
| 108 |
|
| 109 |
#
|
| 110 |
# Just in case a sysadmin prefers generic symbolic links in
|
| 111 |
# /lib/modules/boot for boot time modules we will load these modules
|
| 112 |
#
|
| 113 |
if [ -n "$(modprobe -l -t boot)" ]
|
| 114 |
then
|
| 115 |
modprobe -a -t boot \* &>/dev/null
|
| 116 |
fi
|
| 117 |
}
|
| 118 |
|
| 119 |
|
| 120 |
# vim:ts=4
|