s243a

findInterfaceInfo() - /usr/sbin/net-setup.sh (puppylinux)

Oct 7th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.23 KB | None | 0 0
  1. # Lines 1645 to 1762 of /usr/sbin/net-setup.sh (puppylinux)
  2. # http://www.pearltrees.com/s243a/findinterfaceinfo-puppylinux/id16432971
  3. # Dougal: a function to find info about interface:
  4. findInterfaceInfo()
  5. {
  6.   local INT="$1"
  7.   TYPE=""
  8.   INFO=""
  9.    
  10.   local DEVICE=$(readlink /sys/class/net/$INT/device)
  11.   DEVICE=${DEVICE##*/}
  12.  
  13.   FI_DRIVER=$(readlink /sys/class/net/$INT/device/driver)
  14.   case "$FI_DRIVER" in
  15.    */bus/usb*) TYPE="usb" ;;
  16.    */bus/ieee1394*) TYPE="firewire" ;;
  17.    *) # pcmcia and pci apparently both appear as pci...
  18.       if grep "^${FI_DRIVER##*/} " /etc/networkmodules |grep -q 'pcmcia:' ; then
  19.         TYPE="pcmcia"
  20.       else
  21.         TYPE="pci"
  22.       fi
  23.       ;;
  24.   esac
  25.   FI_DRIVER=${FI_DRIVER##*/}
  26.  
  27.   if [ -d "/sys/class/net/$INT/wireless" ] || \
  28.      [ "$FI_DRIVER" = "prism2_usb" ] || \
  29.      grep -q "$INT" /proc/net/wireless
  30.   then INTTYPE="$L_INTTYPE_Wireless"
  31.   else INTTYPE="$L_INTTYPE_Ethernet"
  32.   fi
  33.  
  34.   case "$TYPE" in
  35.    pci|pcmcia) # pci device, get info from scanpci
  36.      ## Try and replace below with actually getting the device and vendor values
  37.      #DEVICE=$(cat /sys/class/net/$INT/device/device)
  38.      read DEVICE <  /sys/class/net/$INT/device/device
  39.      #VENDOR=$(cat /sys/class/net/$INT/device/vendor)
  40.      read VENDOR < /sys/class/net/$INT/device/vendor
  41.      INFO=$(scanpci | grep -Fi -A1 "vendor $VENDOR device $DEVICE" | tail -n1 | cut -d' ' -f1-3,5- | tr -d '[]' | sed 's%Corporation%%g ; s%Co\.%%g ; s%Ltd\.%%g ; s%Inc\.%%g ; s% ,%,%g' | tr -s ' ')
  42.      #DEVICE=${DEVICE#*:}
  43.      #local BUS=${DEVICE%:*}
  44.      #local CARD=${DEVICE#*:} ; CARD=${CARD%.*}
  45.      #local FUNC=${DEVICE#*.}
  46.      #INFO=$(scanpci | grep -Fi -A1 "bus 0x00$BUS cardnum 0x$CARD function 0x$FUNC" | tail -n1 | cut -d' ' -f1-3,5- | tr -d '[]' | sed 's%Corporation%%g ; s%Co\.%%g ; s%Ltd\.%%g ; s% ,%,%g' | tr -s ' ')
  47.      # if nothing found (pcmcia??), try lspci
  48.      if [ ! "$INFO" ];then
  49.        DEVICE=$(readlink /sys/class/net/$INT/device)
  50.        DEVICE=${DEVICE#*:}
  51.        INFO=$(lspci | grep -m1 "^${DEVICE} " | cut -d: -f3- | sed 's%Corporation%%g ; s%Co\.%%g ; s%Ltd\.%%g ; s% ,%,%g ; s%(rev [0-9a-z].)%%g' | tr -s ' ')
  52.      fi
  53.      ;;
  54.    usb) # need to try and find info from both /proc/bus/usb/devices and lsusb
  55.      ## 1) find device and vendor:
  56.      #DEVICE=`cat /sys/class/net/$INT/device/device 2>/dev/null`
  57.      #local VENDOR=`cat /sys/class/net/$INT/device/vendor 2>/dev/null`
  58.      ## those files might not exist...try getting by module name
  59.      #if [ -z "$DEVICE" -o -z "$VENDOR" ] ; then
  60.        #local DEVINFO="`grep -F -B5 "Driver=$FI_DRIVER" /proc/bus/usb/devices | grep  '^P' | tr ' ' '\n' | grep -E 'Vendor|ProdID' | tr '\n' ' '`"
  61.        #DEVICE=${DEVINFO#* } ; DEVICE=${DEVICE#*=} ; DEVICE=${DEVICE% }
  62.        #VENDOR=${DEVINFO%% *} ; VENDOR=${VENDOR#*=}
  63.      #fi
  64.      ## 2) try looking for info in /proc/bus/usb/devices
  65.      #if [ -n "$DEVICE" -a -n "$VENDOR" ] ; then
  66.        #grep -Fi -A2 "Vendor=$VENDOR ProdID=$DEVICE" /proc/bus/usb/devices | grep '^S:' >/tmp/proc-info
  67.        ### /tmp/proc-info can be blank, have lines with bad info or lines with good info...
  68.        #local MANU="`grep -F 'Manufacturer=' /tmp/proc-info | cut -d= -f2`"
  69.        #local PROD="`grep -F 'Product=' /tmp/proc-info | cut -d= -f2`"
  70.        #rm /tmp/proc-info
  71.        ### need to somehow decide if info (assuming we got it) is good
  72.        ### (maybe if we have MANU or not)
  73.        #if [ -n "$MANU" -a -n "$PROD" ] ; then
  74.          #case "$PROD" in
  75.           #*"$MANU"*) INFO="$PROD" ;;
  76.           #*) INFO="$MANU $PROD" ;;
  77.          #esac
  78.        #else
  79.          ## 3) try looking is lsusb output:
  80.          #INFO="`lsusb -d $VENDOR:$DEVICE 2>/dev/null| head -n1 | cut -d' ' -f7-`"
  81.        #fi
  82.      #fi
  83.      
  84.      # possible alternative to all the above:
  85.      # get the link to the device in dir in /sys/devices
  86.      # (we only want the part of the top dir for it, like usb1/1-8
  87.      local DEV_LINK=$(readlink /sys/class/net/$INT/device | grep -o ".*/usb[0-9]/[0-9]-[0-9]*")
  88.      if [ -z "$DEV_LINK" ] ; then
  89.        DEV_LINK=$(readlink /sys/class/net/$INT | grep -o ".*/usb[0-9]/[0-9]-[0-9]*")
  90.        read PROD < /sys/class/net/$DEV_LINK/product
  91.        read MANU < /sys/class/net/$DEV_LINK/manufacturer
  92.      else
  93.        read PROD < /sys/class/net/$INT/$DEV_LINK/product
  94.        read MANU < /sys/class/net/$INT/$DEV_LINK/manufacturer
  95.      fi
  96.      if [ -n "$MANU" -a -n "$PROD" ] ; then
  97.        case "$PROD" in
  98.          *"$MANU"*) INFO="$PROD" ;;
  99.          *) INFO="$MANU $PROD" ;;
  100.        esac
  101.      else # get info from module
  102.        INFO=$(modinfo $FI_DRIVER |grep -m1 '^description' |tr -s ' ' |cut -d' ' -f2-)
  103.      fi
  104.      ;;
  105.    #pcmcia) # I have no idea... try something generic
  106.      # 1) find device and vendor:
  107.    #  DEVICE=$(cat /sys/class/net/$INT/device/device)
  108.    #  local VENDOR=$(cat /sys/class/net/$INT/device/vendor)
  109.      # maybe use lspcmcia?
  110.    #  ;;
  111.    firewire)
  112.      FI_DRIVER="eth1394"
  113.      INFO="$L_INFO_Eth_Firewire"
  114.      ;;
  115.   esac
  116.   #111015 strip out chars that might upset gtkdialog...
  117.   [ "$MANU" ] && MANU="`echo -n "$MANU" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
  118.   [ "$PROD" ] && PROD="`echo -n "$PROD" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
  119.   [ "$INFO" ] && INFO="`echo -n "$INFO" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
  120. } # end findInterfaceInfo
Add Comment
Please, Sign In to add comment