first whack at usb networking/wifi cards, let's see how it goes

This commit is contained in:
inxi-svn 2011-04-30 05:44:46 +00:00
parent fa7ce4ab41
commit 406bcaecf1

165
inxi
View file

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 1.4.86 #### version: 1.4.87
#### Date: April 26 2011 #### Date: April 29 2011
######################################################################## ########################################################################
#### SPECIAL THANKS #### SPECIAL THANKS
######################################################################## ########################################################################
@ -454,12 +454,16 @@ DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
# $'\1' gets weird results : # $'\1' gets weird results :
# user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v # user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v
# 00000000 01 01 6f 6e 65 20 74 77 6f 0a |..one two.| # 00000000 01 01 6f 6e 65 20 74 77 6f 0a |..one two.|
A_NORMAL_BANS=( corporation communications gmbh technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" "®" $'\2'"\(rev ..\)" ) A_NORMAL_BANS=( corporation communications gmbh technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. corp. "(tm)" "(r)" "®" $'\2'"\(rev ..\)" )
A_CPU_BANS=( @ cpu deca 'dual core' dual-core 'tri core' tri-core 'quad core' quad-core ennea genuine hepta hexa multi octa penta 'processor' processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" ) A_CPU_BANS=( @ cpu deca 'dual core' dual-core 'tri core' tri-core 'quad core' quad-core ennea genuine hepta hexa multi octa penta 'processor' processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" )
# after processing, the ban arrays will be put into these: # after processing, the ban arrays will be put into these:
BAN_LIST_NORMAL='' BAN_LIST_NORMAL=''
BAN_LIST_CPU='' BAN_LIST_CPU=''
### USB networking search string data, because some brands can have other products than
### wifi/nic cards, they need further identifiers, with wildcards.
USB_NETWORK_SEARCH="Atmel Linksys Netgear Realtek.*Network Realtek.*Wireless Realtek.*WLAN"
# WARNING: In the main part below (search for 'KONVI') # WARNING: In the main part below (search for 'KONVI')
# there's a check for Konversation-specific config files. # there's a check for Konversation-specific config files.
# Any one of these can override the above if inxi is run # Any one of these can override the above if inxi is run
@ -2101,8 +2105,13 @@ get_audio_data()
usb_id=$( cat $usb_proc_file/usbid ) usb_id=$( cat $usb_proc_file/usbid )
usb_data=$( $lsusb_path -v 2>/dev/null | grep "$usb_id" ) usb_data=$( $lsusb_path -v 2>/dev/null | grep "$usb_id" )
log_function_data 'raw' "usb_data:\n$usb_data" log_function_data 'raw' "usb_data:\n$usb_data"
usb_data=$( gawk '{ usb_data=$( gawk '
BEGIN {
IGNORECASE=1
}
{
gsub( /,/, " ", $0 ) gsub( /,/, " ", $0 )
gsub(/'"$BAN_LIST_NORMAL"'/, "", $0)
for( i=7; i <= NF; i++ ) { for( i=7; i <= NF; i++ ) {
printf( $i " " ) printf( $i " " )
} }
@ -3279,6 +3288,51 @@ get_networking_data()
} }
}') ) }') )
IFS="$ORIGINAL_IFS" IFS="$ORIGINAL_IFS"
# now we'll check for usb wifi, a work in progress
# USB_NETWORK_SEARCH
# alsa usb detection by damentz
# for every sound card symlink in /proc/asound - display information about it
lsusb_path=$( type -p lsusb )
# if lsusb exists, the file is a symlink, and contains an important usb exclusive file: continue
if [[ -n $lsusb_path ]]; then
# send error messages of lsusb to /dev/null as it will display a bunch if not a super user
# also, find the contents of usbid in lsusb and print everything after the 7th word on the
# corresponding line. Finally, strip out commas as they will change the driver :)
lsusb_data="$( $lsusb_path 2>/dev/null )"
for needle in $USB_NETWORK_SEARCH
do
if [[ -n $( grep -isE "$needle" <<< "$lsusb_data" ) ]];then
card_data=$( grep -isE "$needle" <<< "$lsusb_data" )
fi
done
log_function_data 'raw' "lsusb_data:\n$lsusb_data\ncard_data:$card_data"
if [[ -n $card_data ]];then
array_string=$( gawk '
BEGIN {
IGNORECASE=1
string=""
separator=""
}
{
gsub( /,/, " ", $0 )
gsub(/'"$BAN_LIST_NORMAL"'/, "", $0)
for ( i=7; i<= NF; i++ ) {
string = string separator $i
separator = " "
}
if ( $6 != "" ){
print string ",,,,usb-" $6
}
}' <<< "$card_data" )
if [[ -n $array_string ]];then
array_count=${#A_AUDIO_DATA[@]}
A_NETWORK_DATA[$array_count]="$array_string"
fi
fi
fi
if [[ $B_SHOW_ADVANCED_NETWORK == 'true' ]];then if [[ $B_SHOW_ADVANCED_NETWORK == 'true' ]];then
get_network_advanced_data get_network_advanced_data
fi fi
@ -3291,41 +3345,64 @@ get_network_advanced_data()
{ {
eval $LOGFS eval $LOGFS
local a_network_adv_working='' if_path='' working_path='' local a_network_adv_working='' if_path='' working_path=''
local if_id='' speed='' duplex='' mac_id='' oper_state='' local if_id='' speed='' duplex='' mac_id='' oper_state=''
local usb_vendor='' usb_product='' product_path=''
for (( i=0; i < ${#A_NETWORK_DATA[@]}; i++ )) for (( i=0; i < ${#A_NETWORK_DATA[@]}; i++ ))
do do
IFS="," IFS=","
a_network_adv_working=( ${A_NETWORK_DATA[i]} ) a_network_adv_working=( ${A_NETWORK_DATA[i]} )
# reset these every go round
if_id=''
speed=''
duplex=''
mac_id=''
oper_state=''
if [[ -z $( grep '^usb-' <<< ${a_network_adv_working[4]} ) ]];then
working_path="/sys/bus/pci/devices/0000:${a_network_adv_working[4]}" working_path="/sys/bus/pci/devices/0000:${a_network_adv_working[4]}"
if [[ -e $working_path/net ]];then else
if_path=$( ls $working_path/net 2>/dev/null ) usb_vendor=$( cut -d ':' -f 1 <<< ${a_network_adv_working[4]} )
if_id=$if_path usb_product=$( cut -d ':' -f 2 <<< ${a_network_adv_working[4]} )
working_path=$working_path/net/$if_path # this grep returns the path plus the contents of the file, with a colon separator, so slice that off
# 2.6.32 debian lenny kernel shows not: /net/eth0 but /net:eth0 working_path=$( grep -s "$usb_vendor" /sys/devices/pci*/*/usb*/*/idVendor | sed "s/idVendor:$usb_vendor//" )
else product_path=$( grep -s "$usb_product" /sys/devices/pci*/*/usb*/*/idProduct | sed "s/idProduct:$usb_product//" )
if_path=$( ls $working_path 2>/dev/null | grep 'net:' ) # make sure it's the right product/vendor match here, it will almost always be but let's be sure
if_id=$( cut -d ':' -f 2 <<< "$if_path" ) if [[ -n $working_path && -n $product_path ]] && [[ $working_path == $product_path ]];then
working_path=$working_path/$if_path # now ls that directory and get the numeric starting sub directory and that should be the full path
# to the /net directory part
dir_path=$( ls ${working_path} | grep -sE '^[0-9]' )
working_path="${working_path}${dir_path}"
fi fi
fi
if [[ -n $if_path ]];then
if [[ -f $working_path/speed ]];then if [[ -e $working_path/net ]];then
speed=$( cat $working_path/speed ) if_path=$( ls $working_path/net 2>/dev/null )
fi if_id=$if_path
if [[ -f $working_path/duplex ]];then working_path=$working_path/net/$if_path
duplex=$( cat $working_path/duplex ) # 2.6.32 debian lenny kernel shows not: /net/eth0 but /net:eth0
fi else
if [[ -f $working_path/address ]];then if_path=$( ls $working_path 2>/dev/null | grep 'net:' )
mac_id=$( cat $working_path/address ) if_id=$( cut -d ':' -f 2 <<< "$if_path" )
fi working_path=$working_path/$if_path
if [[ -f $working_path/operstate ]];then fi
oper_state=$( cat $working_path/operstate )
fi if [[ -n $if_path ]];then
if [[ -f $working_path/speed ]];then
speed=$( cat $working_path/speed )
fi fi
if [[ -f $working_path/duplex ]];then
A_NETWORK_DATA[i]=${a_network_adv_working[0]}","${a_network_adv_working[1]}","${a_network_adv_working[2]}","${a_network_adv_working[3]}","${a_network_adv_working[4]}","$if_id","$oper_state","$speed","$duplex","$mac_id duplex=$( cat $working_path/duplex )
IFS="$ORIGINAL_IFS" fi
if [[ -f $working_path/address ]];then
mac_id=$( cat $working_path/address )
fi
if [[ -f $working_path/operstate ]];then
oper_state=$( cat $working_path/operstate )
fi
fi
A_NETWORK_DATA[i]=${a_network_adv_working[0]}","${a_network_adv_working[1]}","${a_network_adv_working[2]}","${a_network_adv_working[3]}","${a_network_adv_working[4]}","$if_id","$oper_state","$speed","$duplex","$mac_id
IFS="$ORIGINAL_IFS"
done done
eval $LOGFE eval $LOGFE
@ -5101,7 +5178,8 @@ print_networking_data()
{ {
eval $LOGFS eval $LOGFS
local i='' card_one='Card-1' network_data='' a_network_working='' port_data='' driver_data='' local i='' card_one='Card-1' network_data='' a_network_working='' port_data='' driver_data=''
local card_string='' port_plural='' module_version='' pci_bus_id='' local card_string='' port_plural='' module_version='' pci_bus_id='' bus_usb_text=''
local bus_usb_id=''
# set A_NETWORK_DATA # set A_NETWORK_DATA
get_networking_data get_networking_data
@ -5127,8 +5205,16 @@ print_networking_data()
fi fi
port_data=" ${C1}port$port_plural${C2} ${a_network_working[2]}" port_data=" ${C1}port$port_plural${C2} ${a_network_working[2]}"
fi fi
if [[ -n ${a_network_working[4]} && $B_EXTRA_DATA == 'true' ]];then if [[ -n ${a_network_working[4]} && $B_EXTRA_DATA == 'true' ]];then
pci_bus_id=" ${C1}busID:${C2} ${a_network_working[4]}" if [[ -z $( grep '^usb-' <<< ${a_network_working[4]} ) ]];then
bus_usb_text='busID'
bus_usb_id=${a_network_working[4]}
else
bus_usb_text='USB-ID'
bus_usb_id=$( cut -d '-' -f '2-4' <<< ${a_network_working[4]} )
fi
pci_bus_id=" ${C1}$bus_usb_text:${C2} $bus_usb_id"
fi fi
card_string='' card_string=''
@ -5160,7 +5246,14 @@ print_networking_data()
port_data=" ${C1}port$port_plural${C2} ${a_network_working[2]}" port_data=" ${C1}port$port_plural${C2} ${a_network_working[2]}"
fi fi
if [[ -n ${a_network_working[4]} && $B_EXTRA_DATA == 'true' ]];then if [[ -n ${a_network_working[4]} && $B_EXTRA_DATA == 'true' ]];then
pci_bus_id=" ${C1}busID:${C2} ${a_network_working[4]}" if [[ -z $( grep '^usb-' <<< ${a_network_working[4]} ) ]];then
bus_usb_text='busID'
bus_usb_id=${a_network_working[4]}
else
bus_usb_text='USB-ID'
bus_usb_id=$( cut -d '-' -f '2-4' <<< ${a_network_working[4]} )
fi
pci_bus_id=" ${C1}$bus_usb_text:${C2} $bus_usb_id"
fi fi
network_data="${C1}Card-$(( $i + 1 ))${C2} ${a_network_working[0]}$driver_data$port_data$pci_bus_id" network_data="${C1}Card-$(( $i + 1 ))${C2} ${a_network_working[0]}$driver_data$port_data$pci_bus_id"
network_data=$( create_print_line " " "$network_data" ) network_data=$( create_print_line " " "$network_data" )