forked from rwbaumg/admin-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-driver.sh
executable file
·73 lines (65 loc) · 1.71 KB
/
get-driver.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
#
# Find all modules and drivers for a given class device.
# From https://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/ch08s02.html
#
if [ $# != "1" ] ; then
echo
echo "Script to display the drivers and modules for a specified sysfs class device"
echo "usage: $0 <CLASS_NAME>"
echo
echo "example usage:"
echo " $0 sda"
echo "Will show all drivers and modules for the sda block device."
echo
exit 1
fi
if test -e "$1"; then
DEVPATH=$1
else
# find sysfs device directory for device
DEVPATH=$(find /sys/class -name "$1" | head -1)
test -z "$DEVPATH" && DEVPATH=$(find /sys/block -name "$1" | head -1)
test -z "$DEVPATH" && DEVPATH=$(find /sys/bus -name "$1" | head -1)
if ! test -e "$DEVPATH"; then
echo "no device found"
exit 1
fi
fi
echo "looking at sysfs device: $DEVPATH"
if test -L "$DEVPATH"; then
# resolve class device link to device directory
DEVPATH=$(readlink -f "$DEVPATH")
echo "resolve link to: $DEVPATH"
fi
if test -d "$DEVPATH"; then
# resolve old-style "device" link to the parent device
PARENT="$DEVPATH";
while test "$PARENT" != "/"; do
if test -L "$PARENT/device"; then
DEVPATH=$(readlink -f "$PARENT/device")
echo "follow 'device' link to parent: $DEVPATH"
break
fi
PARENT=$(dirname "$PARENT")
done
fi
while test "$DEVPATH" != "/"; do
DRIVERPATH=
DRIVER=
MODULEPATH=
MODULE=
if test -e "$DEVPATH/driver"; then
DRIVERPATH=$(readlink -f "$DEVPATH/driver")
DRIVER=$(basename "$DRIVERPATH")
echo -n "found driver: $DRIVER"
if test -e "$DRIVERPATH/module"; then
MODULEPATH=$(readlink -f "$DRIVERPATH/module")
MODULE=$(basename "$MODULEPATH")
echo -n " from module: $MODULE"
fi
echo
fi
DEVPATH=$(dirname "$DEVPATH")
done
exit 0