#! /bin/bash

for i in /sys/class/net/* /sys/class/infiniband/*; 
do
[[ -f $i ]] && continue
# echo $i | cut -d'/' -f5

export SUBSYSTEM=`udevadm info -a $i | grep SUBSYSTEM== | cut -d '"' -f2`
export DEVPATH=`udevadm info -a $i | grep 'looking at device' | awk -F "'" '{print $2}'`

pci_dev="/sys$(dirname $(dirname $DEVPATH))"
pci_addr="$(basename $pci_dev)"
driver="$(basename "$(readlink -f "$pci_dev/driver")")"
vendor_id="$(cat "$pci_dev/vendor" 2>/dev/null)"
model_id="$(cat "$pci_dev/device" 2>/dev/null)"
phys_switch_id="$(cat "/sys$DEVPATH/phys_switch_id" 2>/dev/null)"
phys_port_name="$(cat "/sys$DEVPATH/phys_port_name" 2>/dev/null)"
# 必要的信息确认
[ "$SUBSYSTEM" == "net" -o "$SUBSYSTEM" == "infiniband" ]     || echo 204
[ -n "$pci_addr" -a -n "$model_id" ]                          || echo 205

name=`echo $i | cut -d'/' -f5`
echo $name _SUBSYSTEM $SUBSYSTEM _pci_dev $pci_dev _pci_addr $pci_addr _driver $driver _vendor_id $vendor_id _model_id $model_id _phys_switch_id $phys_switch_id _phys_port_name $phys_port_name

ACTION=add bash net-name.sh name
echo  $?

done


