[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #! /bin/sh -e 2 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." 9 echo " Version 0.1" 10 exit 1 11 fi 12 13 STDIN= 14 if [ "$1" = "--stdin" ]; then 15 STDIN=1 16 shift 17 fi 18 19 # Set up output if specified. 20 if [ $# -eq 1 ]; then exec > $1; fi 21 22 MODPROBECONF=`mktemp /tmp/modprobe.XXXXXX || tempfile || echo /tmp/modprobe.$$` 23 trap "rm -f $MODPROBECONF" 0 24 25 if [ x"$TESTING_MODPROBE_CONF" != x ]; then 26 cp $TESTING_MODPROBE_CONF $MODPROBECONF 27 elif [ "$STDIN" = "1" ]; then 28 cat > $MODPROBECONF 29 elif [ -x /sbin/modprobe.old ]; then 30 # In sbin. 31 /sbin/modprobe.old -c > $MODPROBECONF 32 elif modprobe.old -c >/dev/null 2>&1; then 33 # Somewhere in path. 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 41 else 42 echo Cannot find old version of modprobe. Giving up. 2>&1 43 exit 1 44 fi 45 46 # Resolve (possibly recursive) alias: args filename alias 47 resolve_alias() 48 { 49 RA_RESOLVE=`grep "^alias[ ][ ]*$2[ ]" -- $1 | awk '{ print $3 }'` 50 if [ x"$RA_RESOLVE" = x ]; then 51 echo $2 52 return 53 fi 54 # Recurse. 55 (resolve_alias $1 "$RA_RESOLVE") 56 } 57 58 # Parse alias: args filename modulename aliasto. 59 parse_alias() 60 { 61 PA_ALIAS=`resolve_alias $1 $3` 62 NAME=`echo $2|sed -e 's/\(block\|char\)-major-\([0-9]\+\)$/\1-major-\2-*/'` 63 64 echo "alias $NAME $PA_ALIAS" 65 } 66 67 # Parse options: args modulename aliasto. 68 parse_options() 69 { 70 # Second arg can be null if grab_noninstall options returns empty. 71 [ x"$2" = x ] || echo "options $1 $2" 72 } 73 74 # Separate out the modprobe options from the module options 75 grab_install_options() 76 { 77 GRAB_OPTS="" 78 GRAB_NEXT=0 79 for grab_i; do 80 case "$grab_i" in 81 -o) GRAB_OPTS="$GRAB_OPTS -o"; GRAB_NEXT=1;; 82 -*) echo Warning: Ignoring unknown alias option "$grab_i" >&2;; 83 *) 84 [ $GRAB_NEXT = 0 ] || GRAB_OPTS="$GRAB_OPTS $grab_i" 85 GRAB_NEXT=0 86 ;; 87 esac 88 done 89 echo "$GRAB_OPTS" 90 } 91 92 grab_noninstall_options() 93 { 94 GRAB_OPTS="" 95 GRAB_NEXT=0 96 for grab_i; do 97 case "$grab_i" in 98 -o) GRAB_NEXT=1;; 99 -*) ;; 100 *) 101 [ $GRAB_NEXT = 1 ] || GRAB_OPTS="$GRAB_OPTS $grab_i" 102 GRAB_NEXT=0 103 ;; 104 esac 105 done 106 echo "$GRAB_OPTS" 107 } 108 109 # Produce a multiple install/remove commands. Args: list, command, separator. 110 multi() 111 { 112 mp_res="" 113 for mp_arg in $1; do 114 if [ x"$mp_res" = x ]; then mp_res="/sbin/$2 $mp_arg"; 115 else mp_res="$mp_res$3}/sbin/$2 $mp_arg"; 116 fi 117 done 118 echo "$mp_res" 119 } 120 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. 124 convert_command() 125 { 126 echo "$@" | sed -e 's,insmod,/sbin/modprobe --ignore-install,' -e 's,rmmod,/sbin/modprobe -r --ignore-remove,' 127 } 128 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/ *$//'`" 133 MODULE="$NAME" 134 NAME="$ADD"; 135 fi 136 #echo "NAME=$NAME MODULE=$MODULE REST=$REST" >&2 137 138 # MODNAME is the converted name for use in variables. 139 MODNAME=`echo $MODULE | tr -c A-Za-z_0-9 _` 140 case "$NAME" in 141 '#'*) : ;; # Comment 142 '') : ;; # Blank line 143 144 keep) # Do nothing. 145 ;; 146 147 alias) 148 if [ x"$REST" = xoff ] || [ x"$REST" = xnull ]; then 149 INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" 150 eval install_$MODNAME=\"/bin/true\" 151 else 152 parse_alias $MODPROBECONF "$MODULE" $REST 153 fi 154 ;; 155 156 options) 157 # Options used to be able to contain extra args to insmod 158 # (eg. -o foo). Not any more. 159 case " $REST" in 160 *' '-[-a-z]*) 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`\" 165 ;; 166 *) 167 parse_options $MODULE "$REST" 168 ;; 169 esac 170 ;; 171 172 above) 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' '; '`\" 178 ;; 179 below) 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\" 185 ;; 186 probe) 187 INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" 188 eval install_$MODNAME=\"`multi "$REST" 'modprobe' ' || '`\" 189 ;; 190 probeall) 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\" 194 ;; 195 post-install) 196 INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" 197 eval post_install_$MODNAME=\"`convert_command "$REST"`\" 198 ;; 199 pre-install) 200 INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" 201 eval pre_install_$MODNAME=\"`convert_command "$REST"`\" 202 ;; 203 install) 204 INSTALL_COMMANDS="$INSTALL_COMMANDS $MODULE" 205 eval install_$MODNAME=\"`convert_command "$REST"`\" 206 ;; 207 post-remove) 208 REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" 209 eval post_remove_$MODNAME=\"`convert_command "$REST"`\" 210 ;; 211 pre-remove) 212 REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" 213 eval pre_remove_$MODNAME=\"`convert_command "$REST"`\" 214 ;; 215 remove) 216 REMOVE_COMMANDS="$REMOVE_COMMANDS $MODULE" 217 eval remove_$MODNAME=\"`convert_command "$REST"`\" 218 ;; 219 include) 220 # Recurse. 221 ($0 $MODULE) 222 ;; 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") 225 ;; 226 227 # Ignore prune lines unless they end in .o or .ko, which would 228 # have an effect. 229 prune) 230 case "$MODULE" in 231 *.ko|*.o) 232 echo "Warning: not translating $NAME $MODULE $REST" >&2 233 ;; 234 esac 235 ;; 236 *) 237 echo "Warning: not translating $NAME $MODULE $REST" >&2 238 ;; 239 esac 240 done < $MODPROBECONF 241 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 251 done 252 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 262 done
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |