/[baselayout]/branches/rc-scripts-1_6/sbin/modules-update
Gentoo

Contents of /branches/rc-scripts-1_6/sbin/modules-update

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1748 - (show annotations) (download)
Fri Dec 9 01:54:15 2005 UTC (8 years, 7 months ago) by vapier
File size: 5756 byte(s)
add support for --verbose --debug --help
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 CFGFILE="/etc/modules.conf"
15 TMPFILE="${CFGFILE}.$$"
16 CFGFILE2="/etc/modprobe.conf"
17 TMPFILE2="${CFGFILE2}.$$"
18 CFGFILE3="/etc/modules.devfs"
19 TMPFILE3="${CFGFILE3}.$$"
20 CFGFILE4="/etc/modprobe.devfs"
21 TMPFILE4="${CFGFILE4}.$$"
22 MODDIR="/etc/modules.d"
23 ARCHDIR="${MODDIR}/arch"
24 HEADER="### This file is automatically generated by modules-update"
25
26 source /sbin/functions.sh
27 esyslog() { :; }
28
29 # Parse command-line
30 VERBOSE=0
31 DEBUG=0
32 FORCE=false
33 ASSUME_KV=
34 while [ -n "$1" ]; do
35 case "$1" in
36 -f|--force|force)
37 FORCE=true ;;
38 --assume-kernel=*)
39 ASSUME_KV=${1#*=} ;;
40 -v|--verbose) ((++VERBOSE)) ;;
41 -d|--debug) DEBUG=1 ;;
42 -V|--version)
43 cat /etc/gentoo-release
44 exit 0 ;;
45 -h|--help)
46 cat <<-EOF
47 Usage: modules-update [options]
48
49 Options:
50 --assume-kernel=KV Assume the kernel is at least version KV
51 -f, --force Force execution in face of bad things
52 -v, --verbose Be a bit more verbose in what we do
53 -d, --debug Helpful debug output
54 -V, --version Dump version info
55 -h, --help This help screen, duh
56 EOF
57 exit 0
58 ;;
59 *)
60 echo "Error: I don't understand $1" >&2
61 exit 1 ;;
62 esac
63 shift
64 done
65
66 [[ ${DEBUG} == "1" ]] && set -x
67
68 # Set kernel version, either from --assume-kernel or uname -r
69 KV=${ASSUME_KV:-$(uname -r)}
70 if [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.5.48) ]]; then
71 KERNEL_2_5=true
72 else
73 KERNEL_2_5=false
74 fi
75
76 set -e
77
78 # Reset the sorting order since we depend on it
79 export LC_COLLATE="C"
80
81 depdir() {
82 dep="`sed -n -e '/[ \t]*depfile=/h;${x;s/[ \t]*depfile=//g;s,/[^/]*$,,p}' ${CFGFILE}`"
83 if [ -z "${dep}" ]
84 then
85 dep="/lib/modules/${KV}"
86 fi
87
88 echo "${dep}"
89 }
90
91 CFGFILES="${CFGFILE}"
92
93 if ${KERNEL_2_5}; then
94 CFGFILES="${CFGFILES} ${CFGFILE2} ${CFGFILE4}"
95 fi
96
97 for x in ${CFGFILES}
98 do
99 if [ -f "${x}" ]
100 then
101 if ! sed -ne 1p "${x}" | egrep -q "^${HEADER}"
102 then
103 echo "Error: the current ${x} is not automatically generated."
104
105 if $FORCE; then
106 echo "force specified, (re)generating file anyway."
107 else
108 echo "Use \"modules-update force\" to force (re)generation."
109 exit 1
110 fi
111 fi
112 fi
113 done
114
115 if [ 0 -ne "`id -u`" ]
116 then
117 echo "You have to be root to do this."
118 exit 2
119 fi
120
121 if [ -e "${CFGFILE}" ]
122 then
123 cp -f "${CFGFILE}" "${CFGFILE}".old
124 fi
125 if ${KERNEL_2_5}; then
126 if [ -e "${CFGFILE2}" ]
127 then
128 cp -f "${CFGFILE2}" "${CFGFILE2}".old
129 fi
130 if [ -e "${CFGFILE4}" ]
131 then
132 cp -f "${CFGFILE4}" "${CFGFILE4}".old
133 fi
134 fi
135
136
137 echo "${HEADER}" > "${TMPFILE}"
138 cat <<EOF >> "${TMPFILE}"
139 #
140 # Please do not edit this file directly. If you want to change or add
141 # anything please take a look at the files in ${MODDIR} and read
142 # the manpage for modules-update.
143 #
144 EOF
145 if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "true" ]
146 then
147 sed -e "s:the files in ${MODDIR}:${CFGFILE}:" \
148 "${TMPFILE}" > "${TMPFILE2}"
149
150 if [ -f "${CFGFILE3}" ]
151 then
152 sed -e "s:the files in ${MODDIR}:${CFGFILE3}:" \
153 "${TMPFILE}" > "${TMPFILE4}"
154 fi
155 fi
156
157 for cfg in "${MODDIR}"/* "${CONF}"
158 do
159 [ -d "${cfg}" ] && continue
160
161 [ ! -r "${cfg}" ] && continue
162
163 # Skip backup and RCS files; fixes bug 20597 (07 May 2004 agriffis)
164 [[ ${cfg} == *~ || ${cfg} == *.bak || ${cfg} == *,v ]] && continue
165
166 echo "### modules-update: start processing ${cfg}" >> "${TMPFILE}"
167
168 if [ -x ${cfg} ]
169 then
170 # $cfg can be executable; nice touch, Wichert! :)
171 "${cfg}" >> "${TMPFILE}"
172 else
173 cat "${cfg}" >> "${TMPFILE}"
174 fi
175
176 echo >> "${TMPFILE}"
177 echo "### modules-update: end processing ${cfg}" >> "${TMPFILE}"
178 echo >> "${TMPFILE}"
179 done
180
181 mv -f "${TMPFILE}" "${CFGFILE}"
182
183 if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "true" ]
184 then
185 # Make sure that generate-modprobe.conf can handle --assume-kernel
186 # if we were called with it.
187 if [[ -n ${ASSUME_KV} ]] && ! grep -qe --assume-kernel \
188 /sbin/generate-modprobe.conf
189 then
190 eerror "Error: modules-update called with --assume-kernel flag, but"
191 eerror "generate-modprobe.conf doesn't understand it. You need to"
192 eerror "install >=module-init-tools-3.0-r2"
193 exit 3
194 fi
195 if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \
196 >> "${TMPFILE2}" 2> "${TMPFILE2}.err"
197 then
198 mv -f "${TMPFILE2}" "${CFGFILE2}"
199 else
200 [[ ${VERBOSE} -gt 0 ]] && cat "${TMPFILE2}.err"
201 ewarn "Warning: could not generate ${CFGFILE2}!"
202 rm -f "${TMPFILE2}"
203 fi
204 rm -f "${TMPFILE2}.err"
205
206 if [ -f "${CFGFILE3}" ]
207 then
208 gawk '$0 !~ /^[[:space:]]*include/ { print $0 }' "${CFGFILE3}" \
209 > "${TMPFILE3}"
210
211 export TESTING_MODPROBE_CONF="${TMPFILE3}"
212 if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \
213 >> "${TMPFILE4}" 2> "${TMPFILE4}.err"
214 then
215 mv -f "${TMPFILE4}" "${CFGFILE4}"
216
217 echo >> "${CFGFILE4}"
218 echo "include /etc/modprobe.conf" >> "${CFGFILE4}"
219 else
220 [[ ${VERBOSE} -gt 0 ]] && cat "${TMPFILE4}.err"
221 ewarn "Warning: could not generate ${CFGFILE4}!"
222 rm -f "${TMPFILE4}"
223 fi
224 rm -f "${TMPFILE3}" "${TMPFILE4}.err"
225 fi
226 fi
227
228 # We also call depmod here to stop insmod from complaining that modules.conf
229 # is more recent then modules.dep
230 #
231 if [ -d "`depdir`" -a -f /proc/modules ]
232 then
233 if [ -f /usr/src/linux/System.map ]; then
234 depmod -a -F /usr/src/linux/System.map ${KV}
235 else
236 ewarn "System.map not found - unable to check symbols"
237 fi
238 fi
239
240
241 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20