Magellan Linux

Contents of /tags/init-0_4_11/magellan-initscripts/sbin/modules-update

Parent Directory Parent Directory | Revision Log Revision Log


Revision 695 - (show annotations) (download)
Sat Mar 22 19:59:33 2008 UTC (16 years, 1 month ago) by (unknown author)
File size: 6642 byte(s)
This commit was manufactured by cvs2svn to create tag 'init-0_4_11'.
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 /etc/init.d/functions
40
41 # 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
61 if [[ $(kernel_major_version) = 2.6 ]]
62 then
63 KERNEL_2_6=true
64 else
65 KERNEL_2_6=false
66 fi
67
68 # Check if $CONF is valid
69 [[ ! -r ${CONF} ]] && CONF=
70
71 set -e
72
73 # Reset the sorting order since we depend on it
74 export LC_COLLATE="C"
75
76 depdir() {
77 dep=$(egrep '[[:space:]]*depfile' ${CFGFILE} 2> /dev/null | tail -n 1 | sed -e 's/depfile=//' -e 's,/[^/]*$,,')
78 [[ -z ${dep} ]] && dep="/lib/modules/${KV}"
79 echo "${dep}"
80 }
81
82 CFGFILES=${CFGFILE}
83 if ${KERNEL_2_6} ; then
84 CFGFILES="${CFGFILES} ${CFGFILE2}"
85 [[ -d /etc/devfs.d ]] && CFGFILES="${CFGFILES} ${CFGFILE4}"
86 fi
87
88 for x in ${CFGFILES} ; do
89 if [[ -f ${x} ]] ; then
90 if ! sed -ne 1p "${x}" | egrep -q "^${HEADER}" ; then
91 # Do not bother if its modutils config file, and we
92 # have a 2.6 kernel without modprobe.old
93 [[ ${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."
98
99 if $FORCE ; then
100 echo "force specified, (re)generating file anyway."
101 else
102 echo "Use \"modules-update force\" to force (re)generation."
103 exit 1
104 fi
105 fi
106 fi
107 done
108
109 generate_config() {
110 local cfg=
111 local conf="$1"
112 local moddir="$2"
113 local tmpfile="$3"
114 local do_mprobe="$4"
115
116 for cfg in "${moddir}"/* "${conf}" ; do
117 [[ -d ${cfg} ]] && continue
118
119 [[ ! -r ${cfg} ]] && continue
120
121 # Skip backup and RCS files; fixes bug 20597 (07 May 2004 agriffis)
122 [[ ${cfg} == *~ || ${cfg} == *.bak || ${cfg} == *,v ]] && continue
123
124 [[ ${do_mprobe} -eq 1 && -e "/etc/modprobe.d/${cfg##*/}" ]] && continue
125
126 echo "### modules-update: start processing ${cfg}" >> "${tmpfile}"
127
128 if [[ -x ${cfg} ]] ; then
129 # $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 return 0
141 }
142
143 if type -p modprobe.old > /dev/null ; then
144 if ${FORCE} || is_older_than ${CFGFILE} ${MODDIR} || \
145 [[ ! -e ${CFGFILE} ]] ; then
146 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
152 fi
153
154 if ${FORCE} || is_older_than ${CFGFILE2} ${MODDIR} || [[ ! -e ${CFGFILE2} ]]; then
155 if [[ -x /sbin/generate-modprobe.conf ]] && ${KERNEL_2_6} ; then
156 # Make sure that generate-modprobe.conf can handle --assume-kernel
157 # if we were called with it.
158 if [[ -n ${ASSUME_KV} ]] && \
159 ! grep -qe --assume-kernel /sbin/generate-modprobe.conf
160 then
161 echo "Error: modules-update called with --assume-kernel flag, but"
162 echo "generate-modprobe.conf doesn't understand it. You need to"
163 echo "install >= module-init-tools-3.0-r5"
164 exit 3
165 fi
166
167 echo "Updating ${CFGFILE2}"
168 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
172 [[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old"
173 mv -f "${TMPFILE2}" "${CFGFILE2}"
174 else
175 #
176 # 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
222 fi
223 fi
224
225 # We also call depmod here to stop insmod from complaining that modules.conf
226 # is more recent then modules.dep
227 if [[ ${CFGFILE2} -nt /lib/modules/${KV}/modules.dep ]] ; then
228 if [[ -d $(depdir) && -f /proc/modules ]] ; then
229 if [[ -f /usr/src/linux/System.map ]] ; then
230 depmod -a -F /usr/src/linux/System.map ${KV}
231 else
232 depmod -a ${KV}
233 fi
234 fi
235 fi
236
237
238 # vim:ts=4

Properties

Name Value
svn:executable *