3 # Naive shell script to translate modules.conf + defaults to modprobe.conf
4 # Normal caveats apply, as with any machine translation.
7 Usage: $0 [--assume-kernel=n.n.n] [--stdin] [modprobe.conf]
8 Converts your current modules setup to modprobe.conf.
9 Don't trust it too much.
17 while [ -n "$1" ] ; do
19 --assume-kernel) KV
=$2; shift;;
20 --assume-kernel=*) KV
=${1#*=};;
28 # Set up output if specified.
29 if [ $# -eq 1 ] ; then
35 MODPROBECONF
=`mktemp /tmp/modprobe.XXXXXX || tempfile || echo /tmp/modprobe.$$`
36 trap "rm -f $MODPROBECONF" 0
40 echo Failed to to run modprobe. Giving up.
1>&2
44 if [ x
"$TESTING_MODPROBE_CONF" != x
]; then
45 cp $TESTING_MODPROBE_CONF $MODPROBECONF
46 elif [ "$STDIN" = "1" ]; then
48 elif [ -x /sbin
/modprobe.old
]; then
50 /sbin
/modprobe.old
-c > $MODPROBECONF || modprobe_abort
51 elif modprobe.old
-c >/dev
/null
2>&1; then
53 modprobe.old
-c > $MODPROBECONF || modprobe_abort
54 elif /sbin
/modprobe
-V 2>/dev
/null |
grep -q 'modprobe version'; then
55 # Running /sbin/modprobe gives old version.
56 /sbin
/modprobe
-c > $MODPROBECONF || modprobe_abort
57 elif modprobe
-V 2>/dev
/null |
grep -q 'modprobe version'; then
58 # Running modprobe gives old version.
59 modprobe
-c > $MODPROBECONF || modprobe_abort
61 echo Cannot
find old version of modprobe. Giving up.
2>&1
65 # Resolve (possibly recursive) alias: args filename alias
68 RA_RESOLVE
=`grep "^alias[ ][ ]*$2[ ]" -- $1 | awk '{ print $3 }'`
69 if [ x
"$RA_RESOLVE" = x
]; then
74 (resolve_alias
$1 "$RA_RESOLVE")
77 # Parse alias: args filename modulename aliasto.
80 PA_ALIAS
=`resolve_alias $1 $3`
81 NAME
=`echo $2|sed -e 's/\(block\|char\)-major-\([0-9]\+\)$/\1-major-\2-*/'`
83 echo "alias $NAME $PA_ALIAS"
86 # Parse options: args modulename aliasto.
89 # Second arg can be null if grab_noninstall options returns empty.
90 [ x
"$2" = x
] ||
echo "options $1 $2"
93 # Separate out the modprobe options from the module options
94 grab_install_options
()
100 -o) GRAB_OPTS
="$GRAB_OPTS -o"; GRAB_NEXT
=1;;
101 -*) echo Warning
: Ignoring unknown
alias option
"$grab_i" >&2;;
103 [ $GRAB_NEXT = 0 ] || GRAB_OPTS
="$GRAB_OPTS $grab_i"
111 grab_noninstall_options
()
120 [ $GRAB_NEXT = 1 ] || GRAB_OPTS
="$GRAB_OPTS $grab_i"
128 # Produce a multiple install/remove commands. Args: list, command, separator.
133 if [ x
"$mp_res" = x
]; then mp_res
="/sbin/$2 $mp_arg";
134 else mp_res
="$mp_res${3}/sbin/$2 $mp_arg";
140 # Install and remove commands frequently refer to insmod and rmmod.
141 # Use "modprobe --ignore-install " and "modprobe -r --ignore-remove" since
142 # our versions of rmmod and insmod are deliberately stupid.
145 echo "$@" |
sed -e 's,insmod,/sbin/modprobe --ignore-install,' -e 's,rmmod,/sbin/modprobe -r --ignore-remove,'
148 while read ADD NAME MODULE REST
; do
149 # Ignore a spurious add, otherwise move them down.
150 if [ x
"$ADD" = x
"add" ]; then :; else
151 REST
="`echo $MODULE $REST | sed 's/ *$//'`"
155 #echo "NAME=$NAME MODULE=$MODULE REST=$REST" >&2
157 # MODNAME is the converted name for use in variables.
158 MODNAME
=`echo $MODULE | tr -c A-Za-z_0-9 _`
161 '') : ;; # Blank line
167 if [ x
"$REST" = xoff
] ||
[ x
"$REST" = xnull
]; then
168 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
169 eval install_
$MODNAME=\"/bin
/true
\"
171 parse_alias
$MODPROBECONF "$MODULE" $REST
176 # Options used to be able to contain extra args to insmod
177 # (eg. -o foo). Not any more.
180 parse_options
$MODULE `grab_noninstall_options $REST`
181 INSTALL_OPTIONS
=`grab_install_options $REST`
182 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
183 eval install_
$MODNAME=\"/sbin
/modprobe
$INSTALL_OPTIONS --ignore-install `resolve_alias $MODPROBECONF $MODULE`\"
186 parse_options
$MODULE "$REST"
192 # Pull in these modules after me.
193 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
194 eval post_install_
$MODNAME=\"`multi "$REST" 'modprobe' '; '`\
; /bin
/true
\"
195 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
196 eval pre_remove_
$MODNAME=\"`multi "$REST" 'modprobe -r' '; '`\"
199 # Pull in these modules before me.
200 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
201 eval pre_install_
$MODNAME=\"`multi "$REST" 'modprobe' '; '`\"
202 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
203 eval post_remove_
$MODNAME=\"`multi "$REST" 'modprobe -r' '; '`\
; /bin
/true
\"
206 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
207 eval install_
$MODNAME=\"`multi "$REST" 'modprobe' ' || '`\"
210 # Not quite correct. If they all fail, we should fail.
211 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
212 eval install_
$MODNAME=\"`multi "$REST" 'modprobe' '; '`\
; /bin
/true
\"
215 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
216 eval post_install_
$MODNAME=\"`convert_command "$REST"`\"
219 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
220 eval pre_install_
$MODNAME=\"`convert_command "$REST"`\"
223 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
224 eval install_
$MODNAME=\"`convert_command "$REST"`\"
227 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
228 eval post_remove_
$MODNAME=\"`convert_command "$REST"`\"
231 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
232 eval pre_remove_
$MODNAME=\"`convert_command "$REST"`\"
235 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
236 eval remove_
$MODNAME=\"`convert_command "$REST"`\"
242 # Ignore default lines which are not required any more.
243 "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")
246 # Ignore prune lines unless they end in .o or .ko, which would
251 echo "Warning: not translating $NAME $MODULE $REST" >&2
256 echo "Warning: not translating $NAME $MODULE $REST" >&2
261 for mod
in `echo $INSTALL_COMMANDS | tr ' ' '\n' | sort -u`; do
262 # MODNAME is the converted name for use in variables.
263 MODNAME
=`echo $mod | tr -c A-Za-z_0-9 _`
264 eval PREINSTALL
=\"\
$pre_install_$MODNAME\"
265 eval POSTINSTALL
=\"\
$post_install_$MODNAME\"
266 eval INSTALL
=\"\$\
{install_
$MODNAME:-/sbin
/modprobe
--first-time --ignore-install $mod}\"
267 if [ -n "$PREINSTALL" ]; then PREINSTALL
="{ $PREINSTALL; } ; "; fi
268 if [ -n "$POSTINSTALL" ]; then POSTINSTALL
="&& { $POSTINSTALL; }"; fi
269 echo install $mod $PREINSTALL $INSTALL $POSTINSTALL
272 for mod
in `echo $REMOVE_COMMANDS | tr ' ' '\n' | sort -u`; do
273 # MODNAME is the converted name for use in variables.
274 MODNAME
=`echo $mod | tr -c A-Za-z_0-9 _`
275 eval PREREMOVE
=\"\
$pre_remove_$MODNAME\"
276 eval POSTREMOVE
=\"\
$post_remove_$MODNAME\"
277 eval REMOVE
=\"\$\
{remove_
$MODNAME:-/sbin
/modprobe
-r --first-time --ignore-remove $mod}\"
278 if [ -n "$PREREMOVE" ]; then PREREMOVE
="{ $PREREMOVE; } ; "; fi
279 if [ -n "$POSTREMOVE" ]; then POSTREMOVE
="&& { $POSTREMOVE; }"; fi
280 echo remove
$mod $PREREMOVE $REMOVE $POSTREMOVE