Contents of /tags/init-0_3_5-r4/magellan-initscripts/sbin/generate-modprobe.conf
Parent Directory | Revision Log
Revision 277 -
(show annotations)
(download)
Fri Oct 21 15:24:55 2005 UTC (18 years, 11 months ago) by (unknown author)
File size: 8954 byte(s)
Fri Oct 21 15:24:55 2005 UTC (18 years, 11 months ago) by (unknown author)
File size: 8954 byte(s)
This commit was manufactured by cvs2svn to create tag 'init-0_3_5-r4'.
1 | #!/bin/bash |
2 | # |
3 | # Naive shell script to translate modules.conf + defaults to modprobe.conf |
4 | # Normal caveats apply, as with any machine translation. |
5 | # |
6 | # Updated 07 May 2004 by Aron Griffis <agriffis@gentoo.org> to support |
7 | # --assume-kernel option for Gentoo LiveCD building. See |
8 | # http://bugs.gentoo.org/show_bug.cgi?id=49926 |
9 | |
10 | # Parse command-line |
11 | STDIN= |
12 | KV=`uname -r` |
13 | while [[ "$1" == --* ]]; do |
14 | case "$1" in |
15 | --assume-kernel=*) |
16 | KV=${1#*=} |
17 | ;; |
18 | --stdin) |
19 | STDIN=1 |
20 | ;; |
21 | *) |
22 | echo "Usage: $0 [--stdin] [--assume-kernel=n.n.n] [modprobe.conf]" |
23 | echo " Converts your current modules setup to modprobe.conf." |
24 | echo " Don't trust it too much." |
25 | echo " Version 0.1" |
26 | exit 1 |
27 | ;; |
28 | esac |
29 | shift |
30 | done |
31 | |
32 | # Set up output if specified. |
33 | if [ $# -eq 1 ]; then exec > $1; fi |
34 | |
35 | MODPROBECONF=`mktemp /tmp/modprobe.XXXXXX || tempfile || echo /tmp/modprobe.$$` |
36 | trap "rm -f $MODPROBECONF" 0 |
37 | |
38 | if [ x"$TESTING_MODPROBE_CONF" != x ]; then |
39 | cp $TESTING_MODPROBE_CONF $MODPROBECONF |
40 | elif [ "$STDIN" = "1" ]; then |
41 | cat > $MODPROBECONF |
42 | elif [ -x /sbin/modprobe.old ]; then |
43 | # In sbin. |
44 | /sbin/modprobe.old -c > $MODPROBECONF |
45 | elif modprobe.old -c >/dev/null 2>&1; then |
46 | # Somewhere in path. |
47 | modprobe.old -c > $MODPROBECONF |
48 | elif /sbin/modprobe -V 2>/dev/null | grep -q 'modprobe version'; then |
49 | # Running /sbin/modprobe gives old version. |
50 | /sbin/modprobe -c > $MODPROBECONF |
51 | elif modprobe -V 2>/dev/null | grep -q 'modprobe version'; then |
52 | # Running modprobe gives old version. |
53 | modprobe -c > $MODPROBECONF |
54 | else |
55 | echo Cannot find old version of modprobe. Giving up. 2>&1 |
56 | exit 1 |
57 | fi |
58 | |
59 | # Resolve (possibly recursive) alias: args filename alias |
60 | resolve_alias() |
61 | { |
62 | RA_RESOLVE=`grep "^alias[ ][ ]*$2[ ]" -- $1 | awk '{ print $3 }'` |
63 | if [ x"$RA_RESOLVE" = x ]; then |
64 | echo $2 |
65 | return |
66 | fi |
67 | # Recurse. |
68 | (resolve_alias $1 "$RA_RESOLVE") |
69 | } |
70 | |
71 | # Parse alias: args filename modulename aliasto. |
72 | parse_alias() |
73 | { |
74 | PA_ALIAS=`resolve_alias $1 $3` |
75 | NAME=`echo $2|sed -e 's/\(block\|char\)-major-\([0-9]\+\)$/\1-major-\2-*/'` |
76 | |
77 | echo "alias $NAME $PA_ALIAS" |
78 | } |
79 | |
80 | # Parse options: args modulename aliasto. |
81 | parse_options() |
82 | { |
83 | # Second arg can be null if grab_noninstall options returns empty. |
84 | [ x"$2" = x ] || echo "options $1 $2" |
85 | } |
86 | |
87 | # Separate out the modprobe options from the module options |
88 | grab_install_options() |
89 | { |
90 | GRAB_OPTS="" |
91 | GRAB_NEXT=0 |
92 | for grab_i; do |
93 | case "$grab_i" in |
94 | -o) GRAB_OPTS="$GRAB_OPTS -o"; GRAB_NEXT=1;; |
95 | -*) echo Warning: Ignoring unknown alias option "$grab_i" >&2;; |
96 | *) |
97 | [ $GRAB_NEXT = 0 ] || GRAB_OPTS="$GRAB_OPTS $grab_i" |
98 | GRAB_NEXT=0 |
99 | ;; |
100 | esac |
101 | done |
102 | echo "$GRAB_OPTS" |
103 | } |
104 | |
105 | grab_noninstall_options() |
106 | { |
107 | GRAB_OPTS="" |
108 | GRAB_NEXT=0 |
109 | for grab_i; do |
110 | case "$grab_i" in |
111 | -o) GRAB_NEXT=1;; |
112 | -*) ;; |
113 | *) |
114 | [ $GRAB_NEXT = 1 ] || GRAB_OPTS="$GRAB_OPTS $grab_i" |
115 | GRAB_NEXT=0 |
116 | ;; |
117 | esac |
118 | done |
119 | echo "$GRAB_OPTS" |
120 | } |
121 | |
122 | # Produce a multiple install/remove commands. Args: list, command, separator. |
123 | multi() |
124 | { |
125 | mp_res="" |
126 | for mp_arg in $1; do |
127 | if [ x"$mp_res" = x ]; then mp_res="/sbin/$2 $mp_arg"; |
128 | else mp_res="$mp_res${3}/sbin/$2 $mp_arg"; |
129 | fi |
130 | done |
131 | echo "$mp_res" |
132 | } |
133 | |
134 | # Install and remove commands frequently refer to insmod and rmmod. |
135 | # Use "modprobe --ignore-install " and "modprobe -r --ignore-remove" since |
136 | # our versions of rmmod and insmod are deliberately stupid. |
137 | convert_command() |
138 | { |
139 | echo "$@" | sed -e 's,insmod,/sbin/modprobe --ignore-install,' -e 's,rmmod,/sbin/modprobe -r --ignore-remove,' |
140 | } |
141 | |
142 | while read ADD NAME MODULE REST; do |
143 | # Ignore a spurious add, otherwise move them down. |
144 | if [ x"$ADD" = x"add" ]; then :; else |
145 | REST="`echo $MODULE $REST | sed 's/ *$//'`" |
146 | MODULE="$NAME" |
147 | NAME="$ADD"; |
148 | fi |
149 | #echo "NAME=$NAME MODULE=$MODULE REST=$REST" >&2 |
150 | |
151 | # MODNAME is the converted name for use in variables. |
152 | MODNAME=`echo $MODULE | tr -c A-Za-z_0-9 _` |
153 | case "$NAME" in |
154 | '#'*) : ;; # Comment |
155 | '') : ;; # Blank line |
156 | |
157 | keep) # Do nothing. |
158 | ;; |
159 | |
160 | alias) |
161 | if [ x"$REST" = xoff -o x"$REST" = xnull ]; then |
162 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
163 | eval install_$MODNAME=\"/bin/true\" |
164 | else |
165 | parse_alias $MODPROBECONF "$MODULE" $REST |
166 | fi |
167 | ;; |
168 | |
169 | options) |
170 | # Options used to be able to contain extra args to insmod |
171 | # (eg. -o foo). Not any more. |
172 | case " $REST" in |
173 | *' '-[-a-z]*) |
174 | parse_options $MODULE `grab_noninstall_options $REST` |
175 | INSTALL_OPTIONS=`grab_install_options $REST` |
176 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
177 | eval install_$MODNAME=\"/sbin/modprobe $INSTALL_OPTIONS --ignore-install `resolve_alias $MODPROBECONF $MODULE`\" |
178 | ;; |
179 | *) |
180 | parse_options $MODULE "$REST" |
181 | ;; |
182 | esac |
183 | ;; |
184 | |
185 | above) |
186 | # Pull in these modules after me. |
187 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
188 | eval post_install_$MODNAME=\"`multi "$REST" 'modprobe' '; '`\; /bin/true\" |
189 | REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" |
190 | eval pre_remove_$MODNAME=\"`multi "$REST" 'modprobe -r' '; '`\" |
191 | ;; |
192 | below) |
193 | # Pull in these modules before me. |
194 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
195 | eval pre_install_$MODNAME=\"`multi "$REST" 'modprobe' '; '`\" |
196 | REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" |
197 | eval post_remove_$MODNAME=\"`multi "$REST" 'modprobe -r' '; '`\; /bin/true\" |
198 | ;; |
199 | probe) |
200 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
201 | eval install_$MODNAME=\"`multi "$REST" 'modprobe' ' || '`\" |
202 | ;; |
203 | probeall) |
204 | # Not quite correct. If they all fail, we should fail. |
205 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
206 | eval install_$MODNAME=\"`multi "$REST" 'modprobe' '; '`\; /bin/true\" |
207 | ;; |
208 | post-install) |
209 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
210 | eval post_install_$MODNAME=\"`convert_command "$REST"`\" |
211 | ;; |
212 | pre-install) |
213 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
214 | eval pre_install_$MODNAME=\"`convert_command "$REST"`\" |
215 | ;; |
216 | install) |
217 | INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" |
218 | eval install_$MODNAME=\"`convert_command "$REST"`\" |
219 | ;; |
220 | post-remove) |
221 | REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" |
222 | eval post_remove_$MODNAME=\"`convert_command "$REST"`\" |
223 | ;; |
224 | pre-remove) |
225 | REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" |
226 | eval pre_remove_$MODNAME=\"`convert_command "$REST"`\" |
227 | ;; |
228 | remove) |
229 | REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" |
230 | eval remove_$MODNAME=\"`convert_command "$REST"`\" |
231 | ;; |
232 | include) |
233 | # Recurse. |
234 | ($0 $MODULE) |
235 | ;; |
236 | # Ignore default lines which are not required any more. |
237 | "path[boot]=/lib/modules/boot"|"path[toplevel]=/lib/modules/$KV"|"path[toplevel]=/lib/modules/2.4"|"path[kernel]=/lib/modules/kernel"|"path[fs]=/lib/modules/fs"|"path[net]=/lib/modules/net"|"path[scsi]=/lib/modules/scsi"|"path[block]=/lib/modules/block"|"path[cdrom]=/lib/modules/cdrom"|"path[ipv4]=/lib/modules/ipv4"|"path[ipv6]=/lib/modules/ipv6"|"path[sound]=/lib/modules/sound"|"path[fc4]=/lib/modules/fc4"|"path[video]=/lib/modules/video"|"path[misc]=/lib/modules/misc"|"path[pcmcia]=/lib/modules/pcmcia"|"path[atm]=/lib/modules/atm"|"path[usb]=/lib/modules/usb"|"path[ide]=/lib/modules/ide"|"path[ieee1394]=/lib/modules/ieee1394"|"path[mtd]=/lib/modules/mtd"|"generic_stringfile=/lib/modules/$KV/modules.generic_string"|"pcimapfile=/lib/modules/$KV/modules.pcimap"|"isapnpmapfile=/lib/modules/$KV/modules.isapnpmap"|"usbmapfile=/lib/modules/$KV/modules.usbmap"|"parportmapfile=/lib/modules/$KV/modules.parportmap"|"ieee1394mapfile=/lib/modules/$KV/modules.ieee1394map"|"pnpbiosmapfile=/lib/modules/$KV/modules.pnpbiosmap"|"depfile=/lib/modules/$KV/modules.dep"|"persistdir=/var/lib/modules/persist") |
238 | ;; |
239 | |
240 | # Ignore prune lines unless they end in .o or .ko, which would |
241 | # have an effect. |
242 | prune) |
243 | case "$MODULE" in |
244 | *.ko|*.o) |
245 | echo "Warning: not translating $NAME $MODULE $REST" >&2 |
246 | ;; |
247 | esac |
248 | ;; |
249 | *) |
250 | echo "Warning: not translating $NAME $MODULE $REST" >&2 |
251 | ;; |
252 | esac |
253 | done < $MODPROBECONF |
254 | |
255 | for mod in `echo $INSTALL_COMMANDS | tr ' ' '\n' | sort -u`; do |
256 | # MODNAME is the converted name for use in variables. |
257 | MODNAME=`echo $mod | tr -c A-Za-z_0-9 _` |
258 | eval PREINSTALL=\"\$pre_install_$MODNAME\" |
259 | eval POSTINSTALL=\"\$post_install_$MODNAME\" |
260 | eval INSTALL=\"\$\{install_$MODNAME:-/sbin/modprobe --first-time --ignore-install $mod}\" |
261 | if [ -n "$PREINSTALL" ]; then PREINSTALL="{ $PREINSTALL; } ; "; fi |
262 | if [ -n "$POSTINSTALL" ]; then POSTINSTALL="&& { $POSTINSTALL; }"; fi |
263 | echo install $mod $PREINSTALL $INSTALL $POSTINSTALL |
264 | done |
265 | |
266 | for mod in `echo $REMOVE_COMMANDS | tr ' ' '\n' | sort -u`; do |
267 | # MODNAME is the converted name for use in variables. |
268 | MODNAME=`echo $mod | tr -c A-Za-z_0-9 _` |
269 | eval PREREMOVE=\"\$pre_remove_$MODNAME\" |
270 | eval POSTREMOVE=\"\$post_remove_$MODNAME\" |
271 | eval REMOVE=\"\$\{remove_$MODNAME:-/sbin/modprobe -r --first-time --ignore-remove $mod}\" |
272 | if [ -n "$PREREMOVE" ]; then PREREMOVE="{ $PREREMOVE; } ; "; fi |
273 | if [ -n "$POSTREMOVE" ]; then POSTREMOVE="&& { $POSTREMOVE; }"; fi |
274 | echo remove $mod $PREREMOVE $REMOVE $POSTREMOVE |
275 | done |
Properties
Name | Value |
---|---|
svn:executable | * |