5604l2

Listing 2. Example Version of /sbin/hotplug

#!/bin/bash

declare -i usb_idVendor
declare -i usb_idProduct

MAP=/lib/modules/`uname -r`/modules.usbmap

usb_map_modules ()
{
  # convert the usb_device_id fields to
  # integers as we read them
  local line module
  declare -i match_flags
  declare -i idVendor idProduct

  # look at each usb_device_id entry
  # collect all matches in $DRIVERS
  while read line
  do
    case "$line" in
      \#*) continue ;;
    esac

    set $line

    module=$1
    match_flags=$2
    idVendor=$3
    idProduct=$4

    : checkmatch $module
    : idVendor $idVendor $usb_idVendor
    if [ 0x0001 -eq $(($match_flags & 0x0001)) ] &&
       [ $idVendor -ne $usb_idVendor ]; then
      continue
    fi

    : idProduct $idProduct $usb_idProduct
    if [ 0x0002 -eq $(($match_flags & 0x0002)) ] &&
       [ $idProduct -ne $usb_idProduct ]; then
      continue
    fi

    # It was a match!
    DRIVERS="$module $DRIVERS"
    : drivers $DRIVERS
  done
}

if [ "$1" = "usb" ]; then
  IFS=/
  set $PRODUCT ''
  usb_idVendor=$1
  usb_idProduct=$2
  IFS="$DEFAULT_IFS"

  usb_map_modules < $MAP

  if [ "$ACTION" = "add" ]; then
    PROGRAM="/sbin/modprobe"
  else
    PROGRAM="/sbin/rmmod"
  fi

  for MODULE in $DRIVERS
  do
    $PROGRAM $MODULE
  done
fi

