home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / bin / hw-detect < prev    next >
Encoding:
Text File  |  2007-04-12  |  20.7 KB  |  829 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4. . /usr/share/debconf/confmodule
  5. #set -x
  6.  
  7. if [ -z "$1" ]; then
  8.     PROGRESSBAR=hw-detect/detect_progress_step
  9. else
  10.     PROGRESSBAR=$1
  11. fi
  12.  
  13. NEWLINE="
  14. "
  15. MISSING_MODULES_LIST=""
  16. SUBARCH="$(archdetect)"
  17.  
  18. finish_install=/usr/lib/finish-install.d/30hw-detect
  19.  
  20. if [ -x /sbin/depmod ]; then
  21.     depmod -a > /dev/null 2>&1 || true
  22. fi
  23.  
  24. # Which discover version to use.  Updated by discover_version()
  25. DISCOVER_VERSION=1
  26.  
  27. # Is hotplug available?  Updated by hotplug_type()
  28. HOTPLUG_TYPE=fake
  29.  
  30. log () {
  31.     logger -t hw-detect "$@"
  32. }
  33.  
  34. is_not_loaded() {
  35.     ! ((cut -d" " -f1 /proc/modules | grep -q "^$1\$") || \
  36.        (cut -d" " -f1 /proc/modules | sed -e 's/_/-/g' | grep -q "^$1\$"))
  37. }
  38.  
  39. is_available () {
  40.     find /lib/modules/$(uname -r)/ | sed 's!.*/!!' | cut -d . -f 1 | \
  41.     grep -q "^$1$"
  42. }
  43.  
  44. # Module as first parameter, description of device the second.
  45. missing_module () {
  46.     if ! in_list "$1" "$MISSING_MODULES_LIST"; then
  47.         if [ -n "$MISSING_MODULES_LIST" ]; then
  48.             MISSING_MODULES_LIST="$MISSING_MODULES_LIST, "
  49.         fi
  50.         MISSING_MODULES_LIST="$MISSING_MODULES_LIST$1 ($2)"
  51.     fi
  52. }
  53.  
  54. # The list can be delimited with spaces or spaces and commas.
  55. in_list() {
  56.     echo "$2" | grep -q "\(^\| \)$1\(,\| \|$\)"
  57. }
  58.  
  59. snapshot_devs() {
  60.     echo -n `grep : /proc/net/dev | sort | cut -d':' -f1`
  61. }
  62.  
  63. compare_devs() {
  64.     local olddevs="$1"
  65.     local devs="$2"
  66.     echo "${devs#$olddevs}" | sed -e 's/^ //'
  67. }
  68.  
  69. load_module() {
  70.     local module="$1"
  71.     local cardname="$2"
  72.     local devs=""
  73.     local olddevs=""
  74.     local newdev=""
  75.  
  76.     old=`cat /proc/sys/kernel/printk`
  77.     echo 0 > /proc/sys/kernel/printk
  78.  
  79.     devs="$(snapshot_devs)"
  80.     if log-output -t hw-detect modprobe -v "$module"; then
  81.         olddevs="$devs"
  82.         devs="$(snapshot_devs)"
  83.         newdevs="$(compare_devs "$olddevs" "$devs")"
  84.  
  85.         # Make sure space is used as a delimiter.
  86.         IFS_SAVE="$IFS"
  87.         IFS=" "
  88.         if [ -n "$newdevs" -a -n "$cardname" ]; then
  89.             mkdir -p /etc/network
  90.             for dev in $newdevs; do
  91.                 echo "${dev}:${cardname}" >> /etc/network/devnames
  92.             done
  93.         fi
  94.         IFS="$IFS_SAVE"
  95.     else   
  96.         log "Error loading '$module'"
  97.         if [ "$module" != floppy ] && [ "$module" != ide-floppy ] && [ "$module" != ide-cd ]; then
  98.             db_subst hw-detect/modprobe_error CMD_LINE_PARAM "modprobe -v $module"
  99.             db_input medium hw-detect/modprobe_error || [ $? -eq 30 ]
  100.             db_go
  101.         fi
  102.     fi
  103.  
  104.     echo $old > /proc/sys/kernel/printk
  105. }
  106.  
  107. load_sr_mod () {
  108.     case "$(uname -r)" in
  109.     2.4*)
  110.         if is_not_loaded "sr_mod"; then
  111.             if is_available "sr_mod"; then
  112.                 db_subst hw-detect/load_progress_step CARDNAME "SCSI CDROM support"
  113.                 db_subst hw-detect/load_progress_step MODULE "sr_mod"
  114.                 db_progress INFO hw-detect/load_progress_step
  115.                 load_module sr_mod
  116.                 register-module sr_mod
  117.             else
  118.                 missing_module sr_mod "SCSI CDROM"
  119.             fi
  120.         fi
  121.         ;;
  122.     esac
  123. }
  124.  
  125. blacklist_de4x5 () {
  126.     cat << EOF >> $finish_install
  127. if [ -e /target/etc/discover.conf ]; then
  128.     touch /target/etc/discover-autoskip.conf
  129.     (echo "# blacklisted since tulip is used instead"; echo skip de4x5 ) >> /target/etc/discover-autoskip.conf
  130. fi
  131. EOF
  132. }
  133.  
  134. discover_version () {
  135.     if type discover >/dev/null 2>&1; then
  136.         # Ugh, Discover 1.x didn't exit with nonzero status if given an
  137.         # unrecognized option!
  138.         DISCOVER_TEST=$(discover --version 2> /dev/null) || true
  139.         if expr "$DISCOVER_TEST" : 'discover 2.*' > /dev/null 2>&1; then
  140.             log "Testing experimental discover version 2."
  141.             DISCOVER_VERSION=2
  142.         else
  143.             log "Using discover version 1."
  144.             DISCOVER_VERSION=1
  145.         fi
  146.     else
  147.         DISCOVER_VERSION=
  148.     fi
  149. }
  150.  
  151. # join hack for discover 2
  152. dumb_join_discover (){
  153.     IFS_SAVE="$IFS"
  154.     IFS="$NEWLINE"
  155.     for i in $MODEL_INFOS; do
  156.         echo $1:$i;
  157.         shift
  158.     done
  159.     IFS="$IFS_SAVE"
  160. }
  161.  
  162. # wrapper for discover command that can distinguish Discover 1.x and 2.x
  163. discover_hw () {
  164.     case "$DISCOVER_VERSION" in
  165.     2)
  166.         dpath=linux/module/name
  167.         dver=`uname -r|cut -d. -f1,2` # Kernel version (e.g. 2.4)
  168.         dflags="-d all -e ata -e pci -e pcmcia -e \
  169.             scsi bridge broadband fixeddisk humaninput modem \
  170.             network optical removabledisk"
  171.  
  172.         MODEL_INFOS=$(discover -t $dflags)
  173.         MODULES=$(discover --data-path=$dpath --data-version=$dver $dflags)
  174.         dumb_join_discover $MODULES
  175.         ;;
  176.     1)
  177.         case "$SUBARCH" in
  178.           sparc/*) sbus=",sbus" ;;
  179.         esac
  180.         discover --format="%m:%V %M\n" --disable-all \
  181.                   --enable=pci,ide,scsi${sbus},pcmcia ide scsi cdrom ethernet bridge |
  182.             sed 's/ $//'
  183.         ;;
  184.     esac
  185. }
  186.  
  187. hotplug_type () {
  188.     if [ -f /proc/sys/kernel/hotplug ]; then
  189.         HOTPLUG_HANDLER="$(cat /proc/sys/kernel/hotplug)"
  190.         case $HOTPLUG_HANDLER in
  191.             ''|/sbin/udevsend)
  192.                 HOTPLUG_TYPE=udev
  193.                 ;;
  194.             *)
  195.                 if [ -d /etc/hotplug ]; then
  196.                     HOTPLUG_TYPE=real
  197.                 else
  198.                     HOTPLUG_TYPE=fake
  199.                 fi
  200.                 ;;
  201.         esac
  202.     else
  203.         HOTPLUG_TYPE=
  204.     fi
  205. }
  206.  
  207. # Some pci chipsets are needed or there can be DMA or other problems.
  208. get_ide_chipset_info() {
  209.     for ide_module in $(find /lib/modules/*/kernel/drivers/ide/pci/ -type f 2>/dev/null); do
  210.         if [ -e $ide_module ]; then
  211.             baseidemod=$(echo $ide_module | sed 's/\.o$//' | sed 's/\.ko$//' | sed 's/.*\///')
  212.             # hpt366 is in the discover database, and causes
  213.             # problems with some other hardware (bug #269823)
  214.             if [ "$baseidemod" != hpt366 ]; then
  215.                 echo "$baseidemod:IDE chipset support"
  216.             fi
  217.         fi
  218.     done
  219. }
  220.  
  221. # Return list of lines formatted "module:Description"
  222. get_detected_hw_info() {
  223.     if [ "${SUBARCH%%/*}" = powerpc ]; then
  224.         discover-mac-io
  225.         if [ "$SUBARCH" = powerpc/chrp_rs6k ] || [ "$SUBARCH" = powerpc/chrp_ibm ]; then
  226.             discover-ibm
  227.         fi
  228.     fi
  229.     if [ "${SUBARCH%%/*}" = sparc ]; then
  230.         discover-sbus
  231.     fi
  232.     discover_hw
  233.     if [ -d /proc/bus/usb ]; then
  234.         echo "usb-storage:USB storage"
  235.     fi
  236. }
  237.  
  238. # NewWorld PowerMacs don't want floppy or ide-floppy, and on some models
  239. # (e.g. G5s) the kernel hangs when loading the module.
  240. get_floppy_info() {
  241.     case $SUBARCH in
  242.         powerpc/powermac_newworld) ;;
  243.         *) echo "floppy:Linux Floppy" ;;
  244.     esac
  245. }
  246.  
  247. get_ide_floppy_info() {
  248.     case $SUBARCH in
  249.         powerpc/powermac_newworld) ;;
  250.         *) echo "ide-floppy:Linux IDE floppy" ;;
  251.     esac
  252. }
  253.  
  254. get_input_info() {
  255.     case "$(uname -r)" in
  256.     2.4*)
  257.         case "$(udpkg --print-architecture)" in
  258.             i386|ia64|amd64)
  259.                 register-module psmouse
  260.             ;;
  261.         esac
  262.     
  263.         case $SUBARCH in
  264.             powerpc/chrp*|powerpc/prep)
  265.                 register-module psmouse
  266.             ;;
  267.         esac
  268.         ;;
  269.     esac
  270. }
  271.  
  272. get_rtc_info() {
  273.     # On i386, this gets loaded by hotplug through isapnp, but that
  274.     # doesn't work on amd64.
  275.     case $SUBARCH in
  276.         amd64/*) register-module rtc ;;
  277.     esac
  278. }
  279.  
  280. # Modules that should load before autodetection.
  281. get_early_manual_hw_info() {
  282.     # Load explicitly rather than implicitly to allow the user to
  283.     # specify parameters when the module is loaded.
  284.     echo "ide-core:Linux IDE support"
  285. }
  286.     
  287. # Manually load modules to enable things we can't detect.
  288. # XXX: This isn't the best way to do this; we should autodetect.
  289. # The order of these modules are important.
  290. get_manual_hw_info() {
  291.     get_floppy_info
  292.     # ide-mod and ide-probe-mod are needed for older (2.4.20) kernels
  293.     echo "ide-mod:Linux IDE driver"
  294.     echo "ide-probe-mod:Linux IDE probe driver"
  295.     get_ide_chipset_info
  296.     echo "ide-detect:Linux IDE detection" # 2.4.x > 20
  297.     echo "ide-generic:Linux IDE support" # 2.6
  298.     get_ide_floppy_info
  299.     echo "ide-disk:Linux ATA DISK"
  300.     echo "ide-cd:Linux ATAPI CD-ROM"
  301.     echo "isofs:Linux ISO 9660 filesystem"
  302.     get_input_info
  303.     get_rtc_info
  304.  
  305.     # on some hppa systems, nic and scsi won't be found because they're
  306.     # not on a bus that discover understands ... 
  307.     if [ "`udpkg --print-architecture`" = hppa ]; then
  308.         echo "lasi_82596:LASI Ethernet"
  309.         register-module lasi_82596
  310.         echo "lasi700:LASI SCSI"
  311.         register-module lasi700
  312.         echo "zalon7xx:Zalon SCSI"
  313.         register-module zalon7xx
  314.     fi
  315.  
  316.     case $SUBARCH in
  317.         powerpc/ps3)
  318.             echo "ps3_storage:PS3 internal HDD/CDROM drives"
  319.             echo "gelic_net:PS3 Gigabit Ethernet"
  320.             register-module snd_ps3
  321.         ;;
  322.     esac
  323. }
  324.  
  325. # Detect discover version
  326. discover_version
  327.  
  328. # Detect hotplug type
  329. hotplug_type
  330.  
  331. # Should be greater than the number of kernel modules we can reasonably
  332. # expect it will ever need to load.
  333. MAX_STEPS=1000
  334. OTHER_STEPS=7
  335. # Use 1/10th of the progress bar for the non-module-load steps.
  336. OTHER_STEPSIZE=$(expr $MAX_STEPS / 10 / $OTHER_STEPS)
  337. db_progress START 0 $MAX_STEPS $PROGRESSBAR
  338.  
  339. # Load queued Cardbus modules, if any, and catch hotplug events.
  340. # We need to do this before the regular PCI detection so that we can
  341. # determine which network cards are Cardbus.
  342. if [ -f /etc/pcmcia/cb_mod_queue ]; then
  343.     if [ "$HOTPLUG_TYPE" = fake ]; then
  344.         saved_hotplug=`cat /proc/sys/kernel/hotplug`
  345.         echo /bin/hotplug-pcmcia >/proc/sys/kernel/hotplug
  346.     fi
  347.     for module in $(cat /etc/pcmcia/cb_mod_queue); do
  348.         log "Loading queued Cardbus module $module"
  349.         modprobe -v $module | logger -t hw-detect
  350.     done
  351.     if [ "$HOTPLUG_TYPE" = fake ]; then
  352.         echo $saved_hotplug >/proc/sys/kernel/hotplug
  353.     fi
  354. fi
  355.  
  356. db_progress INFO hw-detect/detect_progress_step
  357.  
  358. # Load yenta_socket on 2.6 kernels, if hardware is available, so that
  359. # discover will see Cardbus cards.
  360. if [ -d /sys/bus/pci/devices ] && grep -q 0x060700 \
  361.     /sys/bus/pci/devices/*/class && \
  362.     ! grep -q ^yenta_socket /proc/modules; then
  363.     db_subst hw-detect/load_progress_step CARDNAME "Cardbus bridge"
  364.     db_subst hw-detect/load_progress_step MODULE "yenta_socket"
  365.     db_progress INFO hw-detect/load_progress_step
  366.     
  367.     log "Detected Cardbus bridge, loading yenta_socket"
  368.     modprobe -v yenta_socket | logger -t hw-detect
  369.     # Ugly hack, but what's the alternative?
  370.     sleep 3 || true
  371. fi
  372.  
  373. # If using real hotplug, re-run the rc scripts to pick up new modules.
  374. # TODO: this just loads modules itself, rather than handing back a list
  375. case $HOTPLUG_TYPE in
  376.     real)
  377.         /lib/debian-installer/coldplug
  378.         ;;
  379.     udev)
  380.         update-dev
  381.         ;;
  382. esac
  383.  
  384. ALL_HW_INFO=$(get_early_manual_hw_info; get_detected_hw_info; get_manual_hw_info)
  385. db_progress STEP $OTHER_STEPSIZE
  386.  
  387. # Remove modules that are already loaded or not available, and construct
  388. # the list for the question.
  389. LIST=""
  390. PROCESSED=""
  391. AVAIL_MODULES="$(find /lib/modules/$(uname -r)/ | sed 's!.*/!!' | cut -d . -f 1)"
  392. LOADED_MODULES="$(cut -d " " -f 1 /proc/modules) $(cut -d " " -f 1 /proc/modules | sed -e 's/_/-/g')"
  393. IFS_SAVE="$IFS"
  394. IFS="$NEWLINE"
  395. for device in $ALL_HW_INFO; do
  396.     module="${device%%:*}"
  397.     cardname="${device##*:}"
  398.     if [ "$module" != "ignore" -a "$module" != "" ] &&
  399.        ! in_list "$module" "$LOADED_MODULES" &&
  400.        ! in_list "$module" "$PROCESSED"
  401.     then
  402.         if [ -z "$cardname" ]; then
  403.             cardname="[Unknown]"
  404.         fi
  405.         
  406.         if [ "$module" = de4x5 ] && ! in_list "$module" "$AVAIL_MODULES"; then
  407.             log "Using tulip rather than unavailable de4x5"
  408.             blacklist_de4x5
  409.             module=tulip
  410.             tulip_de4x5_hack=1
  411.         fi
  412.         
  413.         if in_list "$module" "$AVAIL_MODULES"; then
  414.             if [ -n "$LIST" ]; then
  415.                 LIST="$LIST, "
  416.             fi
  417.             LIST="$LIST$module ($(echo "$cardname" | sed 's/,/ /g'))"
  418.             PROCESSED="$PROCESSED $module"
  419.         else
  420.             missing_module "$module" "$cardname"
  421.         fi
  422.     fi
  423. done
  424. IFS="$IFS_SAVE"
  425. db_progress STEP $OTHER_STEPSIZE
  426.  
  427. if [ "$LIST" ]; then
  428.     # Ask which modules to install.
  429.     db_subst hw-detect/select_modules list "$LIST"
  430.     db_set hw-detect/select_modules "$LIST"
  431.     db_input medium hw-detect/select_modules || true
  432.     db_go || exit 10 # back up
  433.     db_get hw-detect/select_modules
  434.     LIST="$RET"
  435. fi
  436.  
  437. list_to_lines() {
  438.     echo "$LIST" | sed 's/, /\n/g'
  439. }
  440.  
  441. # Work out amount to step per module load. expr rounds down, so 
  442. # it may not get quite to 100%, but will at least never exceed it.
  443. MODULE_STEPS=$(expr \( $MAX_STEPS - \( $OTHER_STEPS \* $OTHER_STEPSIZE \) \))
  444. if [ "$LIST" ]; then
  445.     MODULE_STEPSIZE=$(expr $MODULE_STEPS / $(list_to_lines | wc -l))
  446. fi
  447.  
  448. IFS="$NEWLINE"
  449.  
  450. for device in $(list_to_lines); do
  451.     module="${device%% *}"
  452.     cardname="`echo $device | cut -d'(' -f2 | sed 's/)$//'`"
  453.     # Restore IFS after extracting the fields.
  454.     IFS="$IFS_SAVE"
  455.  
  456.     if [ -z "$module" ] ; then module="[Unknown]" ; fi
  457.     if [ -z "$cardname" ] ; then cardname="[Unknown]" ; fi
  458.  
  459.     log "Detected module '$module' for '$cardname'"
  460.  
  461.     if is_not_loaded "$module"; then
  462.         db_subst hw-detect/load_progress_step CARDNAME "$cardname"
  463.         db_subst hw-detect/load_progress_step MODULE "$module"
  464.         db_progress INFO hw-detect/load_progress_step
  465.         if [ "$cardname" = "[Unknown]" ]; then
  466.             load_module "$module"
  467.         else
  468.             load_module "$module" "$cardname"
  469.         fi
  470.  
  471.         if [ "$module" = tulip ] && [ "$tulip_de4x5_hack" = 1 ]; then
  472.             log "Forcing use of tulip in installed system (de4x hack)"
  473.             register-module tulip
  474.         fi
  475.     fi
  476.  
  477.     db_progress STEP $MODULE_STEPSIZE
  478.     IFS="$NEWLINE"
  479. done
  480. IFS="$IFS_SAVE"
  481.  
  482. if [ -z "$LIST" ]; then
  483.     db_progress STEP $MODULE_STEPS
  484. fi
  485.  
  486. # If there is an ide bus, then register the ide CD modules so they'll be
  487. # available on the target system for base-config. Disk too, in case root is
  488. # not ide but ide is still used. udev should handle this for 2.6.
  489. if [ -e /proc/ide/ -a "`find /proc/ide/* -type d 2>/dev/null`" != "" ]; then
  490.     case "$(uname -r)" in
  491.     2.4*)
  492.         register-module ide-detect
  493.         register-module ide-cd
  494.         register-module ide-disk
  495.     ;;
  496.     esac
  497. fi
  498.  
  499. case "$(uname -r)" in
  500. 2.4*)
  501.     # always load sd_mod and sr_mod if a scsi controller module was loaded.
  502.     # sd_mod to find the disks, and sr_mod to find the CD-ROMs
  503.     if [ -e /proc/scsi/scsi ] && ! grep -q "Attached devices: none" /proc/scsi/scsi; then
  504.         if grep -q 'Type:[ ]\+Direct-Access' /proc/scsi/scsi && \
  505.            is_not_loaded "sd_mod" && \
  506.            ! grep -q '^[^[:alpha:]]\+sd$' /proc/devices; then
  507.                if is_available "sd_mod"; then
  508.                 db_subst hw-detect/load_progress_step CARDNAME "SCSI disk support"
  509.                 db_subst hw-detect/load_progress_step MODULE "sd_mod"
  510.                 db_progress INFO hw-detect/load_progress_step
  511.                 load_module sd_mod
  512.                 register-module sd_mod
  513.             else
  514.                 missing_module sd_mod "SCSI disk"
  515.             fi
  516.         fi
  517.         db_progress STEP $OTHER_STEPSIZE
  518.         if grep -q 'Type:[ ]\+CD-ROM' /proc/scsi/scsi && \
  519.            ! grep -q '^[^[:alpha:]]\+sr$' /proc/devices; then
  520.             load_sr_mod
  521.         fi
  522.         db_progress STEP $OTHER_STEPSIZE
  523.     fi
  524.     ;;
  525. esac
  526.     
  527. if ! is_not_loaded ohci1394; then
  528.     # if firewire was found, try to enable firewire cd support
  529.     if is_not_loaded sbp2 && is_available scsi_mod; then
  530.         if is_available sbp2; then
  531.             db_subst hw-detect/load_progress_step CARDNAME "FireWire CDROM support"
  532.             db_subst hw-detect/load_progress_step MODULE "sbp2"
  533.             db_progress INFO hw-detect/load_progress_step
  534.             load_module sbp2
  535.         else
  536.             missing_module sbp2 "FireWire CDROM"
  537.         fi
  538.     fi
  539.     register-module sbp2
  540.     db_progress STEP $OTHER_STEPSIZE
  541.     load_sr_mod
  542.     db_progress STEP $OTHER_STEPSIZE
  543.     case "$(uname -r)" in
  544.     2.4*)
  545.         # rescan bus for firewire CD after loading sr_mod
  546.         # (Sometimes this echo fails.)
  547.         echo "scsi add-single-device 0 0 0 0" > /proc/scsi/scsi || true
  548.     ;;
  549.     esac
  550. fi
  551.  
  552. # Always load the printer driver on i386 and amd64; it's hard to autodetect.
  553. case $SUBARCH in
  554.     i386/*|amd64/*)
  555.         register-module lp
  556.         ;;
  557. esac
  558.  
  559. apply_pcmcia_resource_opts() {
  560.     local config_opts=/etc/pcmcia/config.opts
  561.     
  562.     # Idempotency
  563.     if ! [ -f ${config_opts}.orig ]; then
  564.         cp $config_opts ${config_opts}.orig
  565.     fi
  566.     cp ${config_opts}.orig $config_opts
  567.  
  568.     local mode=""
  569.     local rmode=""
  570.     local type=""
  571.     local value=""
  572.     while [ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ]; do
  573.         if [ "$1" = exclude ]; then
  574.             mode=exclude
  575.             rmode=include
  576.             shift
  577.         elif [ "$1" = include ]; then
  578.             mode=include
  579.             rmode=exclude
  580.             shift
  581.         fi
  582.         type="$1"
  583.         shift
  584.         value="$1"
  585.         shift
  586.         
  587.         if grep -q "^$rmode $type $value\$" $config_opts; then
  588.             sed "s/^$rmode $type $value\$/$mode $type $value/" \
  589.                 $config_opts >${config_opts}.new
  590.             mv ${config_opts}.new $config_opts
  591.         else
  592.             echo "$mode $type $value" >>$config_opts
  593.         fi
  594.     done
  595. }
  596.  
  597. # get pcmcia running if possible
  598. PCMCIA_INIT=
  599. if [ -x /etc/init.d/pcmciautils ]; then
  600.     PCMCIA_INIT=/etc/init.d/pcmciautils
  601. elif [ -x /etc/init.d/pcmcia ]; then
  602.     PCMCIA_INIT=/etc/init.d/pcmcia
  603. fi
  604. if [ "$PCMCIA_INIT" ]; then
  605.     if ! [ -e /var/run/cardmgr.pid ]; then
  606.         db_input medium hw-detect/start_pcmcia || true
  607.     fi
  608.     if db_go && db_get hw-detect/start_pcmcia && [ "$RET" = true ]; then
  609.         if ! [ -e /var/run/cardmgr.pid ]; then
  610.             db_input medium hw-detect/pcmcia_resources || true
  611.             db_go || true
  612.             db_get hw-detect/pcmcia_resources || true
  613.             apply_pcmcia_resource_opts $RET
  614.         fi
  615.         
  616.         db_progress INFO hw-detect/pcmcia_step
  617.         
  618.         if [ -e /var/run/cardmgr.pid ]; then
  619.             # Not using $PCMCIA_INIT stop as it
  620.             # uses sleep which is not available and is racey.
  621.             kill -9 $(cat /var/run/cardmgr.pid) 2>/dev/null || true
  622.             rm -f /var/run/cardmgr.pid
  623.         fi
  624.  
  625.         # If hotplugging is available in the kernel, we can use it to
  626.         # load modules for Cardbus cards and tell which network
  627.         # interfaces belong to PCMCIA devices. The former is only
  628.         # necessary on 2.4 kernels, though.
  629.         if [ "$HOTPLUG_TYPE" = fake ]; then
  630.             # Snapshot discover information so we can detect
  631.             # modules for Cardbus cards by later comparison in
  632.             # the hotplug handler. (Only on 2.4 kernels.)
  633.             if expr `uname -r` : "2.4.*" >/dev/null 2>&1; then
  634.                 case "$DISCOVER_VERSION" in
  635.                 2)
  636.                     dpath=linux/module/name
  637.                     dver=`uname -r|cut -d. -f1,2` # Kernel version (e.g. 2.4)
  638.                     dflags="-d all -e pci scsi fixeddisk modem network removabledisk bridge"
  639.             
  640.                     echo `discover --data-path=$dpath --data-version=$dver $dflags` \
  641.                         | sed 's/ $//' >/tmp/pcmcia-discover-snapshot
  642.                     ;;
  643.                 1)
  644.                     discover --format="%m " --disable-all --enable=pci \
  645.                         scsi ide ethernet bridge \
  646.                         | sed 's/ $//' >/tmp/pcmcia-discover-snapshot
  647.                     ;;
  648.                 esac
  649.             fi
  650.         
  651.             # Simple handling of hotplug events during PCMCIA
  652.             # detection
  653.             saved_hotplug=`cat /proc/sys/kernel/hotplug`
  654.             echo /bin/hotplug-pcmcia >/proc/sys/kernel/hotplug
  655.         fi
  656.         
  657.         CARDMGR_OPTS="-f" $PCMCIA_INIT start </dev/null 3<&0 2>&1 \
  658.             | logger -t hw-detect
  659.         
  660.         if [ "$HOTPLUG_TYPE" = fake ]; then
  661.             echo $saved_hotplug >/proc/sys/kernel/hotplug
  662.             rm -f /tmp/pcmcia-discover-snapshot
  663.         fi
  664.  
  665.         db_progress STEP $OTHER_STEPSIZE
  666.     fi
  667.     db_fset hw-detect/start_pcmcia seen true || true
  668. fi
  669.  
  670. gen_pcmcia_devnames() {
  671.     while read line; do
  672.         log "Reading line: $line"
  673.         line="$(echo $line | tr '\t' ' ')"
  674.  
  675.         case "$line" in
  676.             Socket*)
  677.             devname="$(echo $line | cut -d' ' -f3-)"
  678.         ;;
  679.         [0-9]*)
  680.             class="$(echo $line | cut -d' ' -f2)"
  681.             dev="$(echo $line | cut -d' ' -f5)"
  682.  
  683.             if [ "$class" != "network" ]; then
  684.                 devname=""
  685.                 return
  686.             else
  687.                 echo "$dev:$devname" >> /etc/network/devnames
  688.                 echo "$dev" >> /etc/network/devhotplug
  689.             fi
  690.         ;;
  691.         esac
  692.     done
  693. }
  694.  
  695. have_pcmcia=0
  696. case "$(uname -r)" in
  697.     2.4*)
  698.         if [ -e "/proc/bus/pccard/drivers" ]; then
  699.             have_pcmcia=1
  700.         fi
  701.     ;;
  702.     2.6*)
  703.         if ls /sys/class/pcmcia_socket/* >/dev/null 2>&1; then
  704.             have_pcmcia=1
  705.         fi
  706.     ;;
  707. esac
  708.  
  709. # find Cardbus network cards on 2.6 kernels
  710. cardbus_check_netdev()
  711. {
  712.     local socket="$1"
  713.     local netdev="$2"
  714.     if [ -L $netdev/device ] && \
  715.         [ -d $socket/device/$(basename $(readlink $netdev/device)) ]; then
  716.         echo $(basename $netdev) >> /etc/network/devhotplug
  717.     fi
  718. }
  719. if ls /sys/class/pcmcia_socket/* >/dev/null 2>&1; then
  720.     for socket in /sys/class/pcmcia_socket/*; do
  721.         for netdev in /sys/class/net/*; do
  722.             cardbus_check_netdev $socket $netdev
  723.         done
  724.     done
  725. fi
  726.  
  727. if db_get hw-detect/start_pcmcia && [ "$RET" = false ]; then
  728.     have_pcmcia=0
  729. fi
  730.  
  731. # Try to do this only once..
  732. if [ "$have_pcmcia" -eq 1 ] && ! grep -q pcmcia-cs /var/lib/apt-install/queue 2>/dev/null; then
  733.     log "Detected PCMCIA, installing pcmcia-cs."
  734.     apt-install pcmcia-cs || true
  735.     if expr "$(uname -r)" : 2.6 >/dev/null; then
  736.         log "Detected PCMCIA, installing pcmciautils."
  737.         apt-install pcmciautils || true
  738.     fi
  739.  
  740.     echo "mkdir /target/etc/pcmcia 2>/dev/null || true" \
  741.         >>$finish_install
  742.     echo "cp /etc/pcmcia/config.opts /target/etc/pcmcia/config.opts" \
  743.         >>$finish_install
  744.  
  745.     # Determine devnames.
  746.     if [ -f /var/run/stab ]; then
  747.         mkdir -p /etc/network
  748.         gen_pcmcia_devnames < /var/run/stab
  749.     fi
  750. fi
  751.  
  752. # Install appropriate hardware detection tool into target.
  753. if type udevd >/dev/null 2>&1; then
  754.     apt-install udev || true
  755. else
  756.     case "$DISCOVER_VERSION" in
  757.         2)
  758.             apt-install discover || true
  759.             ;;
  760.         1|'')
  761.             apt-install discover1 || true
  762.             ;;
  763.     esac
  764.     if [ -f /proc/sys/kernel/hotplug ]; then
  765.         apt-install hotplug || true
  766.     fi
  767. fi
  768.  
  769. # TODO: should this really be conditional on hotplug support?
  770. if [ -f /proc/sys/kernel/hotplug ]; then
  771.     apt-install usbutils || true
  772. fi
  773.  
  774. # Install acpi (works only for 2.6 kernels)
  775. if [ -d /proc/acpi ]; then
  776.     apt-install acpi || true
  777.     apt-install acpid || true
  778. fi
  779.  
  780. # If hardware has support for pmu, install pbbuttonsd
  781. if [ -d /sys/class/misc/pmu/ ]; then
  782.     apt-install pbbuttonsd || true
  783. fi
  784.  
  785. # Install mouseemu on systems likely to have single-button mice
  786. case $SUBARCH in
  787.     i386/mac|amd64/mac|powerpc/powermac_*)
  788.         apt-install mouseemu || true
  789.     ;;
  790. esac
  791.  
  792. # Install optimised libc based on CPU type.
  793. case "$(udpkg --print-architecture)" in
  794.     i386)
  795.         case "$(grep '^cpu family' /proc/cpuinfo | cut -d: -f2)" in
  796.             " 6"|" 15")
  797.                 # intel 686 or Amd k6.
  798.                 apt-install libc6-i686 || true
  799.                     ;;
  800.         esac
  801.     ;;
  802.     sparc)
  803.         if grep -q '^type.*: sun4u' /proc/cpuinfo ; then
  804.             # sparc v9 or v9b
  805.             if grep -q '^cpu.*: .*UltraSparc III' /proc/cpuinfo; then
  806.                 apt-install libc6-sparcv9b || true
  807.             else
  808.                 apt-install libc6-sparcv9 || true
  809.             fi
  810.         fi
  811.     ;;
  812. esac
  813.  
  814. db_progress SET $MAX_STEPS
  815. db_progress STOP
  816.  
  817. if [ -n "$MISSING_MODULES_LIST" ]; then
  818.     log "Missing modules '$MISSING_MODULES_LIST"
  819. fi
  820.  
  821. sysfs-update-devnames
  822.  
  823. # Let userspace /dev tools rescan the devices.
  824. if type update-dev >/dev/null 2>&1; then
  825.     update-dev
  826. fi
  827.  
  828. exit 0
  829.