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