Skip to content

Commit cbaa19d

Browse files
committed
improve pci info format
1 parent a865172 commit cbaa19d

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

lnxrouter

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -691,36 +691,40 @@ get_interface_mac() {
691691
cat "/sys/class/net/${1}/address"
692692
}
693693

694-
get_interface_pci_info() { # pci id / model / virtual
694+
show_interface_pci_info() { # pci id / model / virtual
695695
is_interface "$1" || return
696696

697697
local device_path
698-
local pci_id
699-
local pci_full
700-
701-
local pci_path
702-
local driver
698+
local bus_id=""
699+
local device_type_and_bus_id="unknown"
700+
local driver=""
701+
local device_fullname=""
703702

704703
device_path="$(readlink -f /sys/class/net/$1)"
705-
pci_path=$device_path/../..
706704

707705
if [[ "$device_path" == "/sys/devices/pci"* ]]; then
708-
pci_id="$(echo "$device_path" | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)"
706+
local pci_path
707+
708+
pci_path=$device_path/../..
709+
710+
if [[ -d "$pci_path/driver" ]] ; then
711+
driver=$(readlink -f "$pci_path/driver" | sed 's/\//\n/g' | tail -n 1)
712+
fi
713+
714+
bus_id="$(echo "$device_path" | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)"
715+
device_type_and_bus_id="PCI: $bus_id"
709716

710717
if which lspci >/dev/null 2>&1 ; then
711-
pci_full="$( lspci -D -nn -s "$pci_id" )"
712-
echo -n " PCI: $pci_full"
713-
else
714-
echo -n " PCI: $pci_id"
718+
device_fullname="$( lspci -D -nn -s "$bus_id" | awk '{$1="" ; print $0}' )"
715719
fi
720+
716721
elif [[ "$device_path" == *"/virtual/"* ]]; then
717-
echo " virtual interface"
722+
device_type_and_bus_id="virtual interface"
718723
fi
719724

720-
if [[ -d "$pci_path/driver" ]] ; then
721-
driver=$(readlink -f "$pci_path/driver" | sed 's/\//\n/g' | tail -n 1)
722-
echo -n " System-already-loaded driver: $driver"
723-
fi
725+
echo "$device_type_and_bus_id"
726+
[[ -n "$driver" ]] && echo "System-already-loaded driver: $driver"
727+
[[ -n "$device_fullname" ]] && echo "$device_fullname"
724728
echo ""
725729
# TODO usb
726730
}
@@ -2081,7 +2085,8 @@ echo
20812085
echo "PID: $$"
20822086

20832087
TARGET_IFACE="$(decide_target_interface)" || exit 1 # judge wired (-i CONN_IFACE) or wireless hotspot (--ap $WIFI_IFACE)
2084-
echo "Target interface is ${TARGET_IFACE} ($(get_interface_mac "$TARGET_IFACE")) $(get_interface_pci_info "$TARGET_IFACE")"
2088+
echo "Target interface is ${TARGET_IFACE} ($(get_interface_mac "$TARGET_IFACE")) "
2089+
show_interface_pci_info "$TARGET_IFACE"
20852090

20862091
if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then
20872092
NEW_MACADDR="$(generate_random_mac)"

0 commit comments

Comments
 (0)