3 |
# This is the modules-update script for Debian GNU/Linux. |
# This is the modules-update script for Debian GNU/Linux. |
4 |
# Written by Wichert Akkerman <wakkerma@debian.org> |
# Written by Wichert Akkerman <wakkerma@debian.org> |
5 |
# Copyright (C) 1998, 1999 Software in the Public Interest |
# 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 |
# Modifications by Daniel Robbins <drobbins@gentoo.org>, Gentoo Technologies, Inc. |
if [[ 0 -ne $(id -u) ]] ; then |
15 |
# 02 Sep 2001 -- Removed "arch" stuff since I see no reason to have support for varying |
echo "You have to be root to do this." |
16 |
# CPU architectures on a single system. |
exit 2 |
17 |
|
fi |
|
# More modifications by Niels Rogalla <niro@magellan-linux.net> for Magellan-Linux |
|
|
# Hacked some entries to fit into Magellan: |
|
|
# functions.sh & kernel-2.5 stuff not needed |
|
|
|
|
|
# 06.09.2004 Added kernel 2.6 stuff <niro@magellan-linux.net> |
|
18 |
|
|
19 |
CFGFILE="/etc/modules.conf" |
CFGFILE="/etc/modules.conf" |
20 |
TMPFILE="${CFGFILE}.$$" |
TMPFILE="${CFGFILE}.$$" |
21 |
CFGFILE2="/etc/modprobe.conf" |
CFGFILE2="/etc/modprobe.conf" |
22 |
TMPFILE2="${CFGFILE2}.$$" |
TMPFILE2="${CFGFILE2}.$$" |
23 |
|
TMPFILE2B="${CFGFILE2}B.$$" |
24 |
CFGFILE3="/etc/modules.devfs" |
CFGFILE3="/etc/modules.devfs" |
25 |
TMPFILE3="${CFGFILE3}.$$" |
TMPFILE3="${CFGFILE3}.$$" |
26 |
CFGFILE4="/etc/modprobe.devfs" |
CFGFILE4="/etc/modprobe.devfs" |
28 |
MODDIR="/etc/modules.d" |
MODDIR="/etc/modules.d" |
29 |
ARCHDIR="${MODDIR}/arch" |
ARCHDIR="${MODDIR}/arch" |
30 |
HEADER="### This file is automatically generated by modules-update" |
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 /etc/init.d/functions |
source /etc/init.d/functions |
40 |
|
|
41 |
KERNEL_2_5="no" |
# Parse command-line |
42 |
|
FORCE=false |
43 |
|
ASSUME_KV= |
44 |
|
while [[ -n $1 ]] ; do |
45 |
|
case "$1" in |
46 |
|
force) |
47 |
|
FORCE=true ;; |
48 |
|
--assume-kernel=*) |
49 |
|
ASSUME_KV=${1#*=} ;; |
50 |
|
*) |
51 |
|
echo "Error: I don't understand $1" |
52 |
|
exit 1 ;; |
53 |
|
esac |
54 |
|
shift |
55 |
|
done |
56 |
|
|
57 |
|
# Set kernel version, either from --assume-kernel or uname -r |
58 |
|
KV=${ASSUME_KV:-$(uname -r)} |
59 |
|
|
60 |
# needed for kernel 2.6 |
# needed for kernel 2.6 |
61 |
if [ "$(kernel_major_version)" == "2.6" ] |
if [[ $(kernel_major_version) = 2.6 ]] |
62 |
then |
then |
63 |
KERNEL_2_5="yes" |
KERNEL_2_6=true |
64 |
|
else |
65 |
|
KERNEL_2_6=false |
66 |
fi |
fi |
67 |
|
|
68 |
|
# Check if $CONF is valid |
69 |
|
[[ ! -r ${CONF} ]] && CONF= |
70 |
|
|
71 |
set -e |
set -e |
72 |
|
|
74 |
export LC_COLLATE="C" |
export LC_COLLATE="C" |
75 |
|
|
76 |
depdir() { |
depdir() { |
77 |
dep="`egrep '[[:space:]]*depfile' ${CFGFILE} | tail -n 1 | sed -e 's/depfile=//' -e 's,/[^/]*$,,'`" |
dep=$(egrep '[[:space:]]*depfile' ${CFGFILE} 2> /dev/null | tail -n 1 | sed -e 's/depfile=//' -e 's,/[^/]*$,,') |
78 |
if [ -z "${dep}" ] |
[[ -z ${dep} ]] && dep="/lib/modules/${KV}" |
|
then |
|
|
dep="/lib/modules/$(uname -r)" |
|
|
fi |
|
|
|
|
79 |
echo "${dep}" |
echo "${dep}" |
80 |
} |
} |
81 |
|
|
82 |
CFGFILES="${CFGFILE}" |
CFGFILES=${CFGFILE} |
83 |
|
if ${KERNEL_2_6} ; then |
84 |
if [ "${KERNEL_2_5}" = "yes" ] |
CFGFILES="${CFGFILES} ${CFGFILE2}" |
85 |
then |
[[ -d /etc/devfs.d ]] && CFGFILES="${CFGFILES} ${CFGFILE4}" |
|
CFGFILES="${CFGFILES} ${CFGFILE2} ${CFGFILE4}" |
|
86 |
fi |
fi |
87 |
|
|
88 |
for x in ${CFGFILES} |
for x in ${CFGFILES} ; do |
89 |
do |
if [[ -f ${x} ]] ; then |
90 |
if [ -f "${x}" ] |
if ! sed -ne 1p "${x}" | egrep -q "^${HEADER}" ; then |
91 |
then |
# Do not bother if its modutils config file, and we |
92 |
if ! sed -ne 1p "${x}" | egrep -q "^${HEADER}" |
# have a 2.6 kernel without modprobe.old |
93 |
then |
[[ ${x} == "${CFGFILE}" ]] && ${KERNEL_2_6} && \ |
94 |
|
! type -p modprobe.old > /dev/null && \ |
95 |
|
continue |
96 |
|
|
97 |
echo "Error: the current ${x} is not automatically generated." |
echo "Error: the current ${x} is not automatically generated." |
98 |
|
|
99 |
if [ "$1" != "force" ] |
if $FORCE ; then |
100 |
then |
echo "force specified, (re)generating file anyway." |
101 |
|
else |
102 |
echo "Use \"modules-update force\" to force (re)generation." |
echo "Use \"modules-update force\" to force (re)generation." |
103 |
exit 1 |
exit 1 |
|
else |
|
|
echo "force specified, (re)generating file anyway." |
|
104 |
fi |
fi |
105 |
fi |
fi |
106 |
fi |
fi |
107 |
done |
done |
108 |
|
|
109 |
if [ 0 -ne "`id -u`" ] |
generate_config() { |
110 |
then |
local cfg= |
111 |
echo "You have to be root to do this." |
local conf="$1" |
112 |
exit 2 |
local moddir="$2" |
113 |
fi |
local tmpfile="$3" |
114 |
|
local do_mprobe="$4" |
115 |
if [ -e "${CFGFILE}" ] |
|
116 |
then |
for cfg in "${moddir}"/* "${conf}" ; do |
117 |
cp -f "${CFGFILE}" "${CFGFILE}".old |
[[ -d ${cfg} ]] && continue |
118 |
fi |
|
119 |
if [ "${KERNEL_2_5}" = "yes" ] |
[[ ! -r ${cfg} ]] && continue |
120 |
then |
|
121 |
if [ -e "${CFGFILE2}" ] |
# Skip backup and RCS files; fixes bug 20597 (07 May 2004 agriffis) |
122 |
then |
[[ ${cfg} == *~ || ${cfg} == *.bak || ${cfg} == *,v ]] && continue |
123 |
cp -f "${CFGFILE2}" "${CFGFILE2}".old |
|
124 |
fi |
[[ ${do_mprobe} -eq 1 && -e "/etc/modprobe.d/${cfg##*/}" ]] && continue |
125 |
if [ -e "${CFGFILE4}" ] |
|
126 |
then |
echo "### modules-update: start processing ${cfg}" >> "${tmpfile}" |
127 |
cp -f "${CFGFILE4}" "${CFGFILE4}".old |
|
128 |
fi |
if [[ -x ${cfg} ]] ; then |
129 |
fi |
# $cfg can be executable; nice touch, Wichert! :) |
130 |
|
"${cfg}" >> "${tmpfile}" |
131 |
|
else |
132 |
|
cat "${cfg}" >> "${tmpfile}" |
133 |
|
fi |
134 |
|
|
135 |
|
echo >> "${tmpfile}" |
136 |
|
echo "### modules-update: end processing ${cfg}" >> "${tmpfile}" |
137 |
|
echo >> "${tmpfile}" |
138 |
|
done |
139 |
|
|
140 |
echo "${HEADER}" > "${TMPFILE}" |
return 0 |
141 |
cat <<EOF >> "${TMPFILE}" |
} |
|
# |
|
|
# Please do not edit this file directly. If you want to change or add |
|
|
# anything please take a look at the files in ${MODDIR} and read |
|
|
# the manpage for modules-update. |
|
|
# |
|
|
EOF |
|
|
if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "yes" ] |
|
|
then |
|
|
sed -e "s:the files in ${MODDIR}:${CFGFILE}:" \ |
|
|
"${TMPFILE}" > "${TMPFILE2}" |
|
142 |
|
|
143 |
if [ -f "${CFGFILE3}" ] |
if type -p modprobe.old > /dev/null ; then |
144 |
then |
if ${FORCE} || is_older_than ${CFGFILE} ${MODDIR} || \ |
145 |
sed -e "s:the files in ${MODDIR}:${CFGFILE3}:" \ |
[[ ! -e ${CFGFILE} ]] ; then |
146 |
"${TMPFILE}" > "${TMPFILE4}" |
echo "Updating ${CFGFILE}" |
147 |
|
echo "${FULLHEADER}" > "${TMPFILE}" |
148 |
|
generate_config "${CONF}" "${MODDIR}" "${TMPFILE}" 0 |
149 |
|
[[ -e ${CFGFILE} ]] && mv -f "${CFGFILE}" "${CFGFILE}.old" |
150 |
|
mv -f "${TMPFILE}" "${CFGFILE}" |
151 |
fi |
fi |
152 |
fi |
fi |
153 |
|
|
154 |
for cfg in "${MODDIR}"/* "${CONF}" |
if ${FORCE} || is_older_than ${CFGFILE2} ${MODDIR} || [[ ! -e ${CFGFILE2} ]]; then |
155 |
do |
if [[ -x /sbin/generate-modprobe.conf ]] && ${KERNEL_2_6} ; then |
156 |
[ -d "${cfg}" ] && continue |
# Make sure that generate-modprobe.conf can handle --assume-kernel |
157 |
|
# if we were called with it. |
158 |
[ ! -r "${cfg}" ] && continue |
if [[ -n ${ASSUME_KV} ]] && \ |
159 |
|
! grep -qe --assume-kernel /sbin/generate-modprobe.conf |
160 |
[ -n "`echo "${cfg}" | awk '!/~$|\.bak$/ { print $0 }'`" ] || continue |
then |
161 |
|
echo "Error: modules-update called with --assume-kernel flag, but" |
162 |
echo "### modules-update: start processing ${cfg}" >> "${TMPFILE}" |
echo "generate-modprobe.conf doesn't understand it. You need to" |
163 |
|
echo "install >= module-init-tools-3.0-r5" |
164 |
if [ -x ${cfg} ] |
exit 3 |
165 |
then |
fi |
|
# $cfg can be executable; nice touch, Wichert! :) |
|
|
"${cfg}" >> "${TMPFILE}" |
|
|
else |
|
|
cat "${cfg}" >> "${TMPFILE}" |
|
|
fi |
|
|
|
|
|
echo >> "${TMPFILE}" |
|
|
echo "### modules-update: end processing ${cfg}" >> "${TMPFILE}" |
|
|
echo >> "${TMPFILE}" |
|
|
done |
|
|
|
|
|
mv -f "${TMPFILE}" "${CFGFILE}" |
|
|
|
|
|
if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "yes" ] |
|
|
then |
|
|
if /sbin/generate-modprobe.conf >> "${TMPFILE2}" 2> /dev/null |
|
|
then |
|
|
mv -f "${TMPFILE2}" "${CFGFILE2}" |
|
|
else |
|
|
echo "Warning: could not generate ${CFGFILE2}!" |
|
|
rm -f "${TMPFILE2}" |
|
|
fi |
|
|
|
|
|
if [ -f "${CFGFILE3}" ] |
|
|
then |
|
|
gawk '$0 !~ /^[[:space:]]*include/ { print $0 }' "${CFGFILE3}" > "${TMPFILE3}" |
|
166 |
|
|
167 |
export TESTING_MODPROBE_CONF="${TMPFILE3}" |
echo "Updating ${CFGFILE2}" |
168 |
if /sbin/generate-modprobe.conf >> "${TMPFILE4}" 2> /dev/null |
echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE2}" |
169 |
|
if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \ |
170 |
|
>> "${TMPFILE2}" 2>/dev/null |
171 |
then |
then |
172 |
mv -f "${TMPFILE4}" "${CFGFILE4}" |
[[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old" |
173 |
|
mv -f "${TMPFILE2}" "${CFGFILE2}" |
|
echo >> "${CFGFILE4}" |
|
|
echo "include /etc/modprobe.conf" >> "${CFGFILE4}" |
|
174 |
else |
else |
175 |
echo "Warning: could not generate ${CFGFILE4}!" |
# |
176 |
rm -f "${TMPFILE4}" |
# If we made it here, it means either generate-modprobe.conf |
177 |
|
# bombed on us, or the user doesn't have modutils installed. |
178 |
|
# If the latter is true, then we should generate modprobe.conf |
179 |
|
# ourselves with any old files laying around in /etc/modules.d. |
180 |
|
# |
181 |
|
rm -f "${TMPFILE2}" |
182 |
|
if type -p modprobe.old > /dev/null ; then |
183 |
|
echo "Warning: could not generate ${CFGFILE2}!" |
184 |
|
else |
185 |
|
echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE2B}" |
186 |
|
generate_config "${CONF}" "${MODDIR}" "${TMPFILE2}" 1 |
187 |
|
export TESTING_MODPROBE_CONF="${TMPFILE2}" |
188 |
|
if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \ |
189 |
|
>> "${TMPFILE2B}" 2> /dev/null |
190 |
|
then |
191 |
|
[[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old" |
192 |
|
mv -f "${TMPFILE2B}" "${CFGFILE2}" |
193 |
|
else |
194 |
|
echo "Warning: could not generate ${CFGFILE2}!" |
195 |
|
rm -f "${TMPFILE2B}" |
196 |
|
fi |
197 |
|
rm -f "${TMPFILE2}" |
198 |
|
fi |
199 |
|
fi |
200 |
|
|
201 |
|
if [[ -f ${CFGFILE3} ]] ; then |
202 |
|
echo "Updating ${CFGFILE4}" |
203 |
|
gawk '$0 !~ /^[[:space:]]*include/ { print $0 }' "${CFGFILE3}" \ |
204 |
|
> "${TMPFILE3}" |
205 |
|
|
206 |
|
echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE4}" |
207 |
|
export TESTING_MODPROBE_CONF="${TMPFILE3}" |
208 |
|
if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \ |
209 |
|
>> "${TMPFILE4}" 2> /dev/null |
210 |
|
then |
211 |
|
[[ -e ${CFGFILE4} ]] && mv -f "${CFGFILE4}" "${CFGFILE4}.old" |
212 |
|
mv -f "${TMPFILE4}" "${CFGFILE4}" |
213 |
|
|
214 |
|
echo >> "${CFGFILE4}" |
215 |
|
echo "include /etc/modprobe.conf" >> "${CFGFILE4}" |
216 |
|
else |
217 |
|
echo "Warning: could not generate ${CFGFILE4}!" |
218 |
|
rm -f "${TMPFILE4}" |
219 |
|
fi |
220 |
|
rm -f "${TMPFILE3}" |
221 |
fi |
fi |
|
rm -f "${TMPFILE3}" |
|
222 |
fi |
fi |
223 |
fi |
fi |
224 |
|
|
225 |
# We also call depmod here to stop insmod from complaining that modules.conf |
# We also call depmod here to stop insmod from complaining that modules.conf |
226 |
# is more recent then modules.dep |
# is more recent then modules.dep |
227 |
# |
if [[ ${CFGFILE2} -nt /lib/modules/${KV}/modules.dep ]] ; then |
228 |
if [ -d "`depdir`" -a -f /proc/modules ] |
if [[ -d $(depdir) && -f /proc/modules ]] ; then |
229 |
then |
if [[ -f /usr/src/linux/System.map ]] ; then |
230 |
depmod -a |
depmod -a -F /usr/src/linux/System.map ${KV} |
231 |
|
else |
232 |
|
depmod -a ${KV} |
233 |
|
fi |
234 |
|
fi |
235 |
fi |
fi |
236 |
|
|
237 |
|
|