3 # Naive shell script to translate modules.conf + defaults to modprobe.conf
4 # Normal caveats apply, as with any machine translation.
5 if [ $# -gt 2 ] ||
[ x
"$1" = x--help
]; then
6 echo "Usage: $0 [--stdin] [modprobe.conf]"
7 echo " Converts your current modules setup to modprobe.conf."
8 echo " Don't trust it too much."
14 if [ "$1" = "--stdin" ]; then
19 # Set up output if specified.
20 if [ $# -eq 1 ]; then exec > $1; fi
22 MODPROBECONF
=`mktemp /tmp/modprobe.XXXXXX || tempfile || echo /tmp/modprobe.$$`
23 trap "rm -f $MODPROBECONF" 0
25 if [ x
"$TESTING_MODPROBE_CONF" != x
]; then
26 cp $TESTING_MODPROBE_CONF $MODPROBECONF
27 elif [ "$STDIN" = "1" ]; then
29 elif [ -x /sbin
/modprobe.old
]; then
31 /sbin
/modprobe.old
-c > $MODPROBECONF
32 elif modprobe.old
-c >/dev
/null
2>&1; then
34 modprobe.old
-c > $MODPROBECONF
35 elif /sbin
/modprobe
-V 2>/dev
/null |
grep -q 'modprobe version'; then
36 # Running /sbin/modprobe gives old version.
37 /sbin
/modprobe
-c > $MODPROBECONF
38 elif modprobe
-V 2>/dev
/null |
grep -q 'modprobe version'; then
39 # Running modprobe gives old version.
40 modprobe
-c > $MODPROBECONF
42 echo Cannot
find old version of modprobe. Giving up.
2>&1
46 # Resolve (possibly recursive) alias: args filename alias
49 RA_RESOLVE
=`grep "^alias[ ][ ]*$2[ ]" -- $1 | awk '{ print $3 }'`
50 if [ x
"$RA_RESOLVE" = x
]; then
55 (resolve_alias
$1 "$RA_RESOLVE")
58 # Parse alias: args filename modulename aliasto.
61 PA_ALIAS
=`resolve_alias $1 $3`
62 NAME
=`echo $2|sed -e 's/\(block\|char\)-major-\([0-9]\+\)$/\1-major-\2-*/'`
64 echo "alias $NAME $PA_ALIAS"
67 # Parse options: args modulename aliasto.
70 # Second arg can be null if grab_noninstall options returns empty.
71 [ x
"$2" = x
] ||
echo "options $1 $2"
74 # Separate out the modprobe options from the module options
75 grab_install_options
()
81 -o) GRAB_OPTS
="$GRAB_OPTS -o"; GRAB_NEXT
=1;;
82 -*) echo Warning
: Ignoring unknown
alias option
"$grab_i" >&2;;
84 [ $GRAB_NEXT = 0 ] || GRAB_OPTS
="$GRAB_OPTS $grab_i"
92 grab_noninstall_options
()
101 [ $GRAB_NEXT = 1 ] || GRAB_OPTS
="$GRAB_OPTS $grab_i"
109 # Produce a multiple install/remove commands. Args: list, command, separator.
114 if [ x
"$mp_res" = x
]; then mp_res
="/sbin/$2 $mp_arg";
115 else mp_res
="$mp_res${3}/sbin/$2 $mp_arg";
121 # Install and remove commands frequently refer to insmod and rmmod.
122 # Use "modprobe --ignore-install " and "modprobe -r --ignore-remove" since
123 # our versions of rmmod and insmod are deliberately stupid.
126 echo "$@" |
sed -e 's,insmod,/sbin/modprobe --ignore-install,' -e 's,rmmod,/sbin/modprobe -r --ignore-remove,'
129 while read ADD NAME MODULE REST
; do
130 # Ignore a spurious add, otherwise move them down.
131 if [ x
"$ADD" = x
"add" ]; then :; else
132 REST
="`echo $MODULE $REST | sed 's/ *$//'`"
136 #echo "NAME=$NAME MODULE=$MODULE REST=$REST" >&2
138 # MODNAME is the converted name for use in variables.
139 MODNAME
=`echo $MODULE | tr -c A-Za-z_0-9 _`
142 '') : ;; # Blank line
148 if [ x
"$REST" = xoff
] ||
[ x
"$REST" = xnull
]; then
149 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
150 eval install_
$MODNAME=\"/bin
/true
\"
152 parse_alias
$MODPROBECONF "$MODULE" $REST
157 # Options used to be able to contain extra args to insmod
158 # (eg. -o foo). Not any more.
161 parse_options
$MODULE `grab_noninstall_options $REST`
162 INSTALL_OPTIONS
=`grab_install_options $REST`
163 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
164 eval install_
$MODNAME=\"/sbin
/modprobe
$INSTALL_OPTIONS --ignore-install `resolve_alias $MODPROBECONF $MODULE`\"
167 parse_options
$MODULE "$REST"
173 # Pull in these modules after me.
174 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
175 eval post_install_
$MODNAME=\"`multi "$REST" 'modprobe' '; '`\
; /bin
/true
\"
176 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
177 eval pre_remove_
$MODNAME=\"`multi "$REST" 'modprobe -r' '; '`\"
180 # Pull in these modules before me.
181 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
182 eval pre_install_
$MODNAME=\"`multi "$REST" 'modprobe' '; '`\"
183 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
184 eval post_remove_
$MODNAME=\"`multi "$REST" 'modprobe -r' '; '`\
; /bin
/true
\"
187 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
188 eval install_
$MODNAME=\"`multi "$REST" 'modprobe' ' || '`\"
191 # Not quite correct. If they all fail, we should fail.
192 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
193 eval install_
$MODNAME=\"`multi "$REST" 'modprobe' '; '`\
; /bin
/true
\"
196 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
197 eval post_install_
$MODNAME=\"`convert_command "$REST"`\"
200 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
201 eval pre_install_
$MODNAME=\"`convert_command "$REST"`\"
204 INSTALL_COMMANDS
="$INSTALL_COMMANDS $MODULE"
205 eval install_
$MODNAME=\"`convert_command "$REST"`\"
208 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
209 eval post_remove_
$MODNAME=\"`convert_command "$REST"`\"
212 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
213 eval pre_remove_
$MODNAME=\"`convert_command "$REST"`\"
216 REMOVE_COMMANDS
="$REMOVE_COMMANDS $MODULE"
217 eval remove_
$MODNAME=\"`convert_command "$REST"`\"
223 # Ignore default lines which are not required any more.
224 "path[boot]=/lib/modules/boot"|
"path[toplevel]=/lib/modules/`uname -r`"|
"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/`uname -r`/modules.generic_string"|
"pcimapfile=/lib/modules/`uname -r`/modules.pcimap"|
"isapnpmapfile=/lib/modules/`uname -r`/modules.isapnpmap"|
"usbmapfile=/lib/modules/`uname -r`/modules.usbmap"|
"parportmapfile=/lib/modules/`uname -r`/modules.parportmap"|
"ieee1394mapfile=/lib/modules/`uname -r`/modules.ieee1394map"|
"pnpbiosmapfile=/lib/modules/`uname -r`/modules.pnpbiosmap"|
"depfile=/lib/modules/`uname -r`/modules.dep"|
"persistdir=/var/lib/modules/persist")
227 # Ignore prune lines unless they end in .o or .ko, which would
232 echo "Warning: not translating $NAME $MODULE $REST" >&2
237 echo "Warning: not translating $NAME $MODULE $REST" >&2
242 for mod
in `echo $INSTALL_COMMANDS | tr ' ' '\n' | sort -u`; do
243 # MODNAME is the converted name for use in variables.
244 MODNAME
=`echo $mod | tr -c A-Za-z_0-9 _`
245 eval PREINSTALL
=\"\
$pre_install_$MODNAME\"
246 eval POSTINSTALL
=\"\
$post_install_$MODNAME\"
247 eval INSTALL
=\"\$\
{install_
$MODNAME:-/sbin
/modprobe
--first-time --ignore-install $mod}\"
248 if [ -n "$PREINSTALL" ]; then PREINSTALL
="{ $PREINSTALL; } ; "; fi
249 if [ -n "$POSTINSTALL" ]; then POSTINSTALL
="&& { $POSTINSTALL; }"; fi
250 echo install $mod $PREINSTALL $INSTALL $POSTINSTALL
253 for mod
in `echo $REMOVE_COMMANDS | tr ' ' '\n' | sort -u`; do
254 # MODNAME is the converted name for use in variables.
255 MODNAME
=`echo $mod | tr -c A-Za-z_0-9 _`
256 eval PREREMOVE
=\"\
$pre_remove_$MODNAME\"
257 eval POSTREMOVE
=\"\
$post_remove_$MODNAME\"
258 eval REMOVE
=\"\$\
{remove_
$MODNAME:-/sbin
/modprobe
-r --first-time --ignore-remove $mod}\"
259 if [ -n "$PREREMOVE" ]; then PREREMOVE
="{ $PREREMOVE; } ; "; fi
260 if [ -n "$POSTREMOVE" ]; then POSTREMOVE
="&& { $POSTREMOVE; }"; fi
261 echo remove
$mod $PREREMOVE $REMOVE $POSTREMOVE