Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Lines 1645 to 1762 of /usr/sbin/net-setup.sh (puppylinux)
- # http://www.pearltrees.com/s243a/findinterfaceinfo-puppylinux/id16432971
- # Dougal: a function to find info about interface:
- findInterfaceInfo()
- {
- local INT="$1"
- TYPE=""
- INFO=""
- local DEVICE=$(readlink /sys/class/net/$INT/device)
- DEVICE=${DEVICE##*/}
- FI_DRIVER=$(readlink /sys/class/net/$INT/device/driver)
- case "$FI_DRIVER" in
- */bus/usb*) TYPE="usb" ;;
- */bus/ieee1394*) TYPE="firewire" ;;
- *) # pcmcia and pci apparently both appear as pci...
- if grep "^${FI_DRIVER##*/} " /etc/networkmodules |grep -q 'pcmcia:' ; then
- TYPE="pcmcia"
- else
- TYPE="pci"
- fi
- ;;
- esac
- FI_DRIVER=${FI_DRIVER##*/}
- if [ -d "/sys/class/net/$INT/wireless" ] || \
- [ "$FI_DRIVER" = "prism2_usb" ] || \
- grep -q "$INT" /proc/net/wireless
- then INTTYPE="$L_INTTYPE_Wireless"
- else INTTYPE="$L_INTTYPE_Ethernet"
- fi
- case "$TYPE" in
- pci|pcmcia) # pci device, get info from scanpci
- ## Try and replace below with actually getting the device and vendor values
- #DEVICE=$(cat /sys/class/net/$INT/device/device)
- read DEVICE < /sys/class/net/$INT/device/device
- #VENDOR=$(cat /sys/class/net/$INT/device/vendor)
- read VENDOR < /sys/class/net/$INT/device/vendor
- 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 ' ')
- #DEVICE=${DEVICE#*:}
- #local BUS=${DEVICE%:*}
- #local CARD=${DEVICE#*:} ; CARD=${CARD%.*}
- #local FUNC=${DEVICE#*.}
- #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 ' ')
- # if nothing found (pcmcia??), try lspci
- if [ ! "$INFO" ];then
- DEVICE=$(readlink /sys/class/net/$INT/device)
- DEVICE=${DEVICE#*:}
- 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 ' ')
- fi
- ;;
- usb) # need to try and find info from both /proc/bus/usb/devices and lsusb
- ## 1) find device and vendor:
- #DEVICE=`cat /sys/class/net/$INT/device/device 2>/dev/null`
- #local VENDOR=`cat /sys/class/net/$INT/device/vendor 2>/dev/null`
- ## those files might not exist...try getting by module name
- #if [ -z "$DEVICE" -o -z "$VENDOR" ] ; then
- #local DEVINFO="`grep -F -B5 "Driver=$FI_DRIVER" /proc/bus/usb/devices | grep '^P' | tr ' ' '\n' | grep -E 'Vendor|ProdID' | tr '\n' ' '`"
- #DEVICE=${DEVINFO#* } ; DEVICE=${DEVICE#*=} ; DEVICE=${DEVICE% }
- #VENDOR=${DEVINFO%% *} ; VENDOR=${VENDOR#*=}
- #fi
- ## 2) try looking for info in /proc/bus/usb/devices
- #if [ -n "$DEVICE" -a -n "$VENDOR" ] ; then
- #grep -Fi -A2 "Vendor=$VENDOR ProdID=$DEVICE" /proc/bus/usb/devices | grep '^S:' >/tmp/proc-info
- ### /tmp/proc-info can be blank, have lines with bad info or lines with good info...
- #local MANU="`grep -F 'Manufacturer=' /tmp/proc-info | cut -d= -f2`"
- #local PROD="`grep -F 'Product=' /tmp/proc-info | cut -d= -f2`"
- #rm /tmp/proc-info
- ### need to somehow decide if info (assuming we got it) is good
- ### (maybe if we have MANU or not)
- #if [ -n "$MANU" -a -n "$PROD" ] ; then
- #case "$PROD" in
- #*"$MANU"*) INFO="$PROD" ;;
- #*) INFO="$MANU $PROD" ;;
- #esac
- #else
- ## 3) try looking is lsusb output:
- #INFO="`lsusb -d $VENDOR:$DEVICE 2>/dev/null| head -n1 | cut -d' ' -f7-`"
- #fi
- #fi
- # possible alternative to all the above:
- # get the link to the device in dir in /sys/devices
- # (we only want the part of the top dir for it, like usb1/1-8
- local DEV_LINK=$(readlink /sys/class/net/$INT/device | grep -o ".*/usb[0-9]/[0-9]-[0-9]*")
- if [ -z "$DEV_LINK" ] ; then
- DEV_LINK=$(readlink /sys/class/net/$INT | grep -o ".*/usb[0-9]/[0-9]-[0-9]*")
- read PROD < /sys/class/net/$DEV_LINK/product
- read MANU < /sys/class/net/$DEV_LINK/manufacturer
- else
- read PROD < /sys/class/net/$INT/$DEV_LINK/product
- read MANU < /sys/class/net/$INT/$DEV_LINK/manufacturer
- fi
- if [ -n "$MANU" -a -n "$PROD" ] ; then
- case "$PROD" in
- *"$MANU"*) INFO="$PROD" ;;
- *) INFO="$MANU $PROD" ;;
- esac
- else # get info from module
- INFO=$(modinfo $FI_DRIVER |grep -m1 '^description' |tr -s ' ' |cut -d' ' -f2-)
- fi
- ;;
- #pcmcia) # I have no idea... try something generic
- # 1) find device and vendor:
- # DEVICE=$(cat /sys/class/net/$INT/device/device)
- # local VENDOR=$(cat /sys/class/net/$INT/device/vendor)
- # maybe use lspcmcia?
- # ;;
- firewire)
- FI_DRIVER="eth1394"
- INFO="$L_INFO_Eth_Firewire"
- ;;
- esac
- #111015 strip out chars that might upset gtkdialog...
- [ "$MANU" ] && MANU="`echo -n "$MANU" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
- [ "$PROD" ] && PROD="`echo -n "$PROD" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
- [ "$INFO" ] && INFO="`echo -n "$INFO" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
- } # end findInterfaceInfo
Add Comment
Please, Sign In to add comment