File: sysfs-update-devnames.sh

package info (click to toggle)
hw-detect 1.142
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,664 kB
  • sloc: sh: 1,408; makefile: 103; perl: 102; ansic: 39
file content (28 lines) | stat: -rwxr-xr-x 1,288 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#! /bin/sh -e
# Make sure that /etc/network/devnames is up to date, using sysfs. In
# hotplug land, we may not get a chance to update it otherwise.

if [ ! -d /sys/class/net ] || ! type lspci >/dev/null 2>&1; then
	exit
fi

for dev in $(grep : /proc/net/dev | sort | cut -d: -f1); do
	if grep "^$dev:" /etc/network/devnames >/dev/null 2>&1; then
		continue
	fi
	if [ -f "/sys/class/net/$dev/device/vendor" ] && \
	   [ -f "/sys/class/net/$dev/device/device" ]; then
		vendor="$(sed 's/^0x//' "/sys/class/net/$dev/device/vendor")"
		device="$(sed 's/^0x//' "/sys/class/net/$dev/device/device")"
		# 'tail -n 1' because for some reason lspci outputs two
		# Device: lines.
		vendorname="$(lspci -d "$vendor:$device" -m -v | grep ^Vendor: | tail -n 1 | sed 's/^Vendor:[[:space:]]*//; s/,/\\,/g')"
		devicename="$(lspci -d "$vendor:$device" -m -v | grep ^Device: | tail -n 1 | sed 's/^Device:[[:space:]]*//; s/,/\\,/g')"
		if [ "$vendorname" ] || [ "$devicename" ]; then
			echo "$dev:$vendorname $devicename" >> /etc/network/devnames
		fi
	elif [ "$(readlink -f /sys/class/net/$dev/device/bus)" = /sys/bus/ieee1394 ] || \
	     [ "$(readlink -f /sys/class/net/$dev/device/bus)" = /sys/bus/firewire ]; then
		echo "$dev:FireWire (IEEE 1394) Ethernet device" >> /etc/network/devnames
	fi
done