| 1 | #!/bin/bash |
| 2 | # Steven Shiau <[email protected]> |
| 3 | # License: GPL |
| 4 | |
| 5 | # Description: hwscan can not load the chip module (like piix)... So here we |
| 6 | # use the results scanned from hwscan, then load them. |
| 7 | # Ref: http://lists.suse.com/archive/suse-linux-e/2005-Aug/0782.html |
| 8 | |
| 9 | # For SuSE |
| 10 | ### BEGIN INIT INFO |
| 11 | # Provides: parse-load-mod-suse |
| 12 | # Required-Start: hwscan boot.coldplug |
| 13 | # Should-Start: |
| 14 | # Required-Stop: |
| 15 | # Default-Start: B |
| 16 | # Default-Stop: |
| 17 | # Description: Load all the modules scanned by hwscan. |
| 18 | ### END INIT INFO |
| 19 | |
| 20 | parse_and_load_modules() { |
| 21 | MOD_MAP=/lib/modules/`uname -r`/modules.pcimap |
| 22 | pcitable_hwdata="/usr/lib/mkpxeinitrd-net/initrd-skel/etc/pcitable" |
| 23 | mod_list="" |
| 24 | echo -n "Mapping the modules from the results of hwscan and lspci if available..." |
| 25 | # Part 1: use the hwscan results |
| 26 | for ihw in /var/lib/hardware/unique-keys/*; do |
| 27 | echo -n "." |
| 28 | if [ -e "$ihw" ]; then |
| 29 | MOD_TMP="$(mktemp /tmp/mod.XXXXXX)" |
| 30 | grep -E "(^VendorID=|^DeviceID=|^SubVendorID=|^SubDeviceID=)" $ihw > $MOD_TMP |
| 31 | . $MOD_TMP |
| 32 | map_mod="$(grep "0x0000${VendorID} 0x0000${DeviceID}" $MOD_MAP | sort | uniq | cut -d" " -f1)" |
| 33 | for im in $map_mod; do |
| 34 | [ -z "$(echo "$mod_list" | grep $im 2>/dev/null)" ] && mod_list="$mod_list $im" |
| 35 | done |
| 36 | [ -f "$MOD_TMP" ] && rm -f $MOD_TMP |
| 37 | fi |
| 38 | done |
| 39 | echo "done!" |
| 40 | # Part 2: since only PCI devices are in modules.pcimap, for SCSI or others, we |
| 41 | # need to use other method. Borrow the hwdata from RedHat. |
| 42 | if [ -x /usr/lib/mkpxeinitrd-net/initrd-skel/sbin/scan_pci ]; then |
| 43 | mod2_list="$(/usr/lib/mkpxeinitrd-net/initrd-skel/sbin/scan_pci /usr/lib/mkpxeinitrd-net/initrd-skel/etc)" |
| 44 | mod_list="$mod_list $mod2_list" |
| 45 | fi |
| 46 | [ -n "$mod_list" ] && echo "The modules to be loaded: $mod_list" |
| 47 | for imod in $mod_list; do |
| 48 | imod_aform="$(echo $imod | sed -e "s/-/_/g")" |
| 49 | if [ -z "$(lsmod | grep "^$imod_aform")" ]; then |
| 50 | echo -n "Loading $imod..." |
| 51 | modprobe $imod |
| 52 | echo "done!" |
| 53 | else |
| 54 | echo "$imod is already loaded, skip this!" |
| 55 | fi |
| 56 | done |
| 57 | } |
| 58 | |
| 59 | case "$1" in |
| 60 | start) |
| 61 | parse_and_load_modules |
| 62 | ;; |
| 63 | stop) |
| 64 | # do nothing. |
| 65 | true |
| 66 | ;; |
| 67 | *) |
| 68 | echo "Usage: $0 start" >&2 |
| 69 | exit 1 |
| 70 | ;; |
| 71 | esac |