| 1 |
#!/bin/bash
|
| 2 |
#
|
| 3 |
# This is the modules-update script for Debian GNU/Linux.
|
| 4 |
# Written by Wichert Akkerman <wakkerma@debian.org>
|
| 5 |
# Copyright (C) 1998, 1999 Software in the Public Interest
|
| 6 |
#
|
| 7 |
# Modifications by Daniel Robbins <drobbins@gentoo.org>, Gentoo Foundation
|
| 8 |
# 02 Sep 2001 -- Removed "arch" stuff since I see no reason to have
|
| 9 |
# support for varying CPU architectures on a single system.
|
| 10 |
#
|
| 11 |
# Updated by Aron Griffis <agriffis@gentoo.org>
|
| 12 |
# 05 May 2004 -- handle --assume-kernel argument for livecd building
|
| 13 |
|
| 14 |
if [[ 0 -ne $(id -u) ]] ; then
|
| 15 |
echo "You have to be root to do this."
|
| 16 |
exit 2
|
| 17 |
fi
|
| 18 |
|
| 19 |
CFGFILE="/etc/modules.conf"
|
| 20 |
TMPFILE="${CFGFILE}.$$"
|
| 21 |
CFGFILE2="/etc/modprobe.conf"
|
| 22 |
TMPFILE2="${CFGFILE2}.$$"
|
| 23 |
TMPFILE2B="${CFGFILE2}B.$$"
|
| 24 |
CFGFILE3="/etc/modules.devfs"
|
| 25 |
TMPFILE3="${CFGFILE3}.$$"
|
| 26 |
CFGFILE4="/etc/modprobe.devfs"
|
| 27 |
TMPFILE4="${CFGFILE4}.$$"
|
| 28 |
MODDIR="/etc/modules.d"
|
| 29 |
ARCHDIR="${MODDIR}/arch"
|
| 30 |
HEADER="### This file is automatically generated by modules-update"
|
| 31 |
FULLHEADER="${HEADER}
|
| 32 |
#
|
| 33 |
# Please do not edit this file directly. If you want to change or add
|
| 34 |
# anything please take a look at the files in ${MODDIR} and read
|
| 35 |
# the manpage for modules-update(8).
|
| 36 |
#
|
| 37 |
"
|
| 38 |
|
| 39 |
source /sbin/functions.sh
|
| 40 |
esyslog() { :; }
|
| 41 |
|
| 42 |
# Parse command-line
|
| 43 |
VERBOSE=0
|
| 44 |
DEBUG=0
|
| 45 |
FORCE="false"
|
| 46 |
ASSUME_KV=
|
| 47 |
while [[ -n $1 ]] ; do
|
| 48 |
case "$1" in
|
| 49 |
-f|--force|force)
|
| 50 |
FORCE="true"
|
| 51 |
;;
|
| 52 |
--assume-kernel=*)
|
| 53 |
ASSUME_KV=${1#*=}
|
| 54 |
;;
|
| 55 |
-v|--verbose)
|
| 56 |
((++VERBOSE))
|
| 57 |
;;
|
| 58 |
-d|--debug)
|
| 59 |
DEBUG=1
|
| 60 |
;;
|
| 61 |
-V|--version)
|
| 62 |
cat /etc/gentoo-release
|
| 63 |
exit 0
|
| 64 |
;;
|
| 65 |
-h|--help)
|
| 66 |
cat <<-EOF
|
| 67 |
Usage: modules-update [options]
|
| 68 |
|
| 69 |
Options:
|
| 70 |
--assume-kernel=KV Assume the kernel is at least version KV
|
| 71 |
-f, --force Force execution in face of bad things
|
| 72 |
-v, --verbose Be a bit more verbose in what we do
|
| 73 |
-d, --debug Helpful debug output
|
| 74 |
-V, --version Dump version info
|
| 75 |
-h, --help This help screen, duh
|
| 76 |
EOF
|
| 77 |
exit 0
|
| 78 |
;;
|
| 79 |
*)
|
| 80 |
eerror "Error: I don't understand $1"
|
| 81 |
exit 1
|
| 82 |
;;
|
| 83 |
esac
|
| 84 |
shift
|
| 85 |
done
|
| 86 |
|
| 87 |
[[ ${DEBUG} == "1" ]] && set -x
|
| 88 |
|
| 89 |
# Set kernel version, either from --assume-kernel or uname -r
|
| 90 |
KV=${ASSUME_KV:-$(uname -r)}
|
| 91 |
if [[ $(KV_to_int ${KV}) -ge "$(KV_to_int 2.5.48)" ]] ; then
|
| 92 |
KERNEL_2_6="true"
|
| 93 |
else
|
| 94 |
KERNEL_2_6="false"
|
| 95 |
fi
|
| 96 |
|
| 97 |
# Check if $CONF is valid
|
| 98 |
[[ ! -r ${CONF} ]] && CONF=
|
| 99 |
|
| 100 |
set -e
|
| 101 |
|
| 102 |
# Reset the sorting order since we depend on it
|
| 103 |
export LC_COLLATE="C"
|
| 104 |
|
| 105 |
depdir() {
|
| 106 |
local dep=$(sed -n -e '/[ \t]*depfile=/h;${x;s/[ \t]*depfile=//g;s,/[^/]*$,,p}' \
|
| 107 |
"${CFGFILE}")
|
| 108 |
[[ -z ${dep} ]] && dep="/lib/modules/${KV}"
|
| 109 |
echo "${dep}"
|
| 110 |
}
|
| 111 |
|
| 112 |
CFGFILES=${CFGFILE}
|
| 113 |
if ${KERNEL_2_6} ; then
|
| 114 |
CFGFILES="${CFGFILES} ${CFGFILE2}"
|
| 115 |
[[ -d /etc/devfs.d ]] && CFGFILES="${CFGFILES} ${CFGFILE4}"
|
| 116 |
fi
|
| 117 |
|
| 118 |
for x in ${CFGFILES} ; do
|
| 119 |
if [[ -f ${x} ]] ; then
|
| 120 |
if ! sed -ne 1p "${x}" | egrep -q "^${HEADER}" ; then
|
| 121 |
# Do not bother if its modutils config file, and we
|
| 122 |
# have a 2.6 kernel without modprobe.old
|
| 123 |
[[ ${x} == "${CFGFILE}" ]] && ${KERNEL_2_6} && \
|
| 124 |
! type -p modprobe.old > /dev/null && \
|
| 125 |
continue
|
| 126 |
|
| 127 |
ewarn "Error: the current ${x} is not automatically generated."
|
| 128 |
|
| 129 |
if ${FORCE} ; then
|
| 130 |
ewarn "force specified, (re)generating file anyway."
|
| 131 |
else
|
| 132 |
eerror "Use \"modules-update force\" to force (re)generation."
|
| 133 |
exit 1
|
| 134 |
fi
|
| 135 |
fi
|
| 136 |
fi
|
| 137 |
done
|
| 138 |
|
| 139 |
generate_config() {
|
| 140 |
local cfg=
|
| 141 |
local conf="$1"
|
| 142 |
local moddir="$2"
|
| 143 |
local tmpfile="$3"
|
| 144 |
local do_mprobe="$4"
|
| 145 |
|
| 146 |
for cfg in "${moddir}"/* "${conf}" ; do
|
| 147 |
[[ -d ${cfg} ]] && continue
|
| 148 |
|
| 149 |
[[ ! -r ${cfg} ]] && continue
|
| 150 |
|
| 151 |
# Skip backup and RCS files; fixes bug 20597 (07 May 2004 agriffis)
|
| 152 |
[[ ${cfg} == *~ || ${cfg} == *.bak || ${cfg} == *,v ]] && continue
|
| 153 |
|
| 154 |
[[ ${do_mprobe} -eq 1 && -e /etc/modprobe.d/${cfg##*/} ]] && continue
|
| 155 |
|
| 156 |
echo "### modules-update: start processing ${cfg}" >> "${tmpfile}"
|
| 157 |
|
| 158 |
if [[ -x ${cfg} ]] ; then
|
| 159 |
# $cfg can be executable; nice touch, Wichert! :)
|
| 160 |
"${cfg}" >> "${tmpfile}"
|
| 161 |
else
|
| 162 |
cat "${cfg}" >> "${tmpfile}"
|
| 163 |
fi
|
| 164 |
|
| 165 |
echo >> "${tmpfile}"
|
| 166 |
echo "### modules-update: end processing ${cfg}" >> "${tmpfile}"
|
| 167 |
echo >> "${tmpfile}"
|
| 168 |
done
|
| 169 |
|
| 170 |
return 0
|
| 171 |
}
|
| 172 |
|
| 173 |
if type -p modprobe.old > /dev/null ; then
|
| 174 |
if ${FORCE} || is_older_than ${CFGFILE} ${MODDIR} || \
|
| 175 |
[[ ! -e ${CFGFILE} ]] ; then
|
| 176 |
ebegin "Updating ${CFGFILE}"
|
| 177 |
echo "${FULLHEADER}" > "${TMPFILE}"
|
| 178 |
generate_config "${CONF}" "${MODDIR}" "${TMPFILE}" 0
|
| 179 |
[[ -e ${CFGFILE} ]] && mv -f "${CFGFILE}" "${CFGFILE}.old"
|
| 180 |
mv -f "${TMPFILE}" "${CFGFILE}"
|
| 181 |
eend 0
|
| 182 |
fi
|
| 183 |
fi
|
| 184 |
|
| 185 |
if ${FORCE} || is_older_than ${CFGFILE2} ${MODDIR} || [[ ! -e ${CFGFILE2} ]] ; then
|
| 186 |
if [[ -x /sbin/generate-modprobe.conf ]] && ${KERNEL_2_6} ; then
|
| 187 |
# Make sure that generate-modprobe.conf can handle --assume-kernel
|
| 188 |
# if we were called with it.
|
| 189 |
if [[ -n ${ASSUME_KV} ]] && \
|
| 190 |
! grep -qe -- --assume-kernel /sbin/generate-modprobe.conf ; then
|
| 191 |
eerror "Error: modules-update called with --assume-kernel flag, but"
|
| 192 |
eerror "generate-modprobe.conf doesn't understand it. You need to"
|
| 193 |
eerror "install >=module-init-tools-3.0-r2"
|
| 194 |
exit 3
|
| 195 |
fi
|
| 196 |
|
| 197 |
ebegin "Updating ${CFGFILE2}"
|
| 198 |
echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE2}"
|
| 199 |
if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \
|
| 200 |
>> "${TMPFILE2}" 2> "${TMPFILE2}.err" ; then
|
| 201 |
[[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old"
|
| 202 |
mv -f "${TMPFILE2}" "${CFGFILE2}"
|
| 203 |
eend 0
|
| 204 |
else
|
| 205 |
#
|
| 206 |
# If we made it here, it means either generate-modprobe.conf
|
| 207 |
# bombed on us, or the user doesn't have modutils installed.
|
| 208 |
# If the latter is true, then we should generate modprobe.conf
|
| 209 |
# ourselves with any old files laying around in /etc/modules.d.
|
| 210 |
#
|
| 211 |
rm -f "${TMPFILE2}"
|
| 212 |
if type -p modprobe.old > /dev/null ; then
|
| 213 |
[[ ${VERBOSE} -gt 0 ]] && cat "${TMPFILE2}.err"
|
| 214 |
eend 1 "Warning: could not generate ${CFGFILE2}!"
|
| 215 |
else
|
| 216 |
echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE2B}"
|
| 217 |
generate_config "${CONF}" "${MODDIR}" "${TMPFILE2}" 1
|
| 218 |
export TESTING_MODPROBE_CONF="${TMPFILE2}"
|
| 219 |
if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \
|
| 220 |
>> "${TMPFILE2B}" 2> "${TMPFILE2B}.err" ; then
|
| 221 |
[[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old"
|
| 222 |
mv -f "${TMPFILE2B}" "${CFGFILE2}"
|
| 223 |
eend 0
|
| 224 |
else
|
| 225 |
[[ ${VERBOSE} -gt 0 ]] && cat "${TMPFILE2B}.err"
|
| 226 |
eend 1 "Warning: could not generate ${CFGFILE2}!"
|
| 227 |
rm -f "${TMPFILE2B}"
|
| 228 |
fi
|
| 229 |
rm -f "${TMPFILE2}" "${TMPFILE2B}.err"
|
| 230 |
fi
|
| 231 |
rm -f "${TMPFILE2}.err"
|
| 232 |
fi
|
| 233 |
|
| 234 |
if [[ -f ${CFGFILE3} ]] ; then
|
| 235 |
ebegin "Updating ${CFGFILE4}"
|
| 236 |
gawk '$0 !~ /^[[:space:]]*include/ { print $0 }' "${CFGFILE3}" \
|
| 237 |
> "${TMPFILE3}"
|
| 238 |
|
| 239 |
echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE4}"
|
| 240 |
export TESTING_MODPROBE_CONF="${TMPFILE3}"
|
| 241 |
if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \
|
| 242 |
>> "${TMPFILE4}" 2> "${TMPFILE4}.err" ; then
|
| 243 |
[[ -e ${CFGFILE4} ]] && mv -f "${CFGFILE4}" "${CFGFILE4}.old"
|
| 244 |
mv -f "${TMPFILE4}" "${CFGFILE4}"
|
| 245 |
|
| 246 |
echo >> "${CFGFILE4}"
|
| 247 |
echo "include /etc/modprobe.conf" >> "${CFGFILE4}"
|
| 248 |
eend 0
|
| 249 |
else
|
| 250 |
[[ ${VERBOSE} -gt 0 ]] && cat "${TMPFILE4}.err"
|
| 251 |
eend 1 "Warning: could not generate ${CFGFILE4}!"
|
| 252 |
rm -f "${TMPFILE4}"
|
| 253 |
fi
|
| 254 |
rm -f "${TMPFILE3}" "${TMPFILE4}.err"
|
| 255 |
fi
|
| 256 |
fi
|
| 257 |
fi
|
| 258 |
|
| 259 |
# We also call depmod here to stop insmod from complaining that modules.conf
|
| 260 |
# is more recent then modules.dep
|
| 261 |
if [[ ${CFGFILE2} -nt /lib/modules/${KV}/modules.dep ]] ; then
|
| 262 |
if [[ -d $(depdir) && -f /proc/modules ]] ; then
|
| 263 |
if [[ -f /lib/modules/${KV}/build/System.map ]] ; then
|
| 264 |
depmod -a -F /lib/modules/${KV}/build/System.map ${KV}
|
| 265 |
else
|
| 266 |
depmod -a ${KV}
|
| 267 |
fi
|
| 268 |
fi
|
| 269 |
fi
|
| 270 |
|
| 271 |
|
| 272 |
# vim:ts=4
|