-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkdetect.sh
executable file
·244 lines (204 loc) · 7.75 KB
/
kdetect.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
#
# kdetect.sh : hardware detection
#
# Copyright (C) 2000,2001,2007 Giacomo Catenazzi <[email protected]>
# This is free software, see GNU General Public License v2 for details.
#
# Version: 2.0 (21.IX.2007)
# Maintainer: Giacomo Catenazzi <[email protected]>
# Mirror: http://people.debian.org/~cate/files/kernautoconfig/
# Mailing List: [email protected]
# Credits:
# Peter Samuelson [scan_PCI function]
# William Stearns and Andreas Schwab [bash v.1 support]
# Andreas Jellinghaus
#
# This script try to autoconfigure the Linux kernel, detecting the
# hardware (devices, ...) and software (protocols, filesystems, ...).
# It uses soft detections: no direct IO access to unknow devices, thus
# it is always safe to run this script and it never hangs, but it cannot
# detect all hardware (mainly some very old hardware).
#
# Report errors, bugs, additions, wishes and comments <[email protected]>.
#
# Usage:
# General Hints:
# you don't need super user privileges.
# you can run this script on a target machine without the need of
# the kernel sources.
#
# Extra information for the developers:
# There are a lots of redundance: because user maybe has not already
# installed the drivers (thus we use smart detection on PCI, USB,..)
# and not all file methods are usable ('lspci' not installed,
# '/proc' not mounted or 'dmesg' not usable).
# We want to check the drivers that system needs, not the drivers
# actually installed on actual system (in this case you should
# simply check the 'System.map').
#
# This is a simple bash shell script. It use only the following external
# program:
# Req: bash[if,echo,test], grep/egrep, sed, uname, which, cp,mv,rm
# Opt: dmesg
# and read this files:
# Opt: /proc/*; /var/log/dmesg; /etc/fstab; linux/drivers/pci/pci.ids
#--- Configuration of kernautoconf ---#
IFS_orig="$IFS"
LANG=C
#--- (Configuration of Autoconfigure) ---#
if [ "x$1" = "x--debug" ] ; then
OUT=/dev/stdout
debug () {
echo "$*"
}
found () {
echo "$*" "# $sub"
}
subsys () {
echo "$*"
sub="$*"
}
else
OUT=kdetect.list
debug () {
:
}
echo "# Generated by kdetect" > $OUT
found () {
echo "$*" >> $OUT
}
subsys () {
:
}
fi
#--- PCI ---#
debug '# PCI detection with lspci'
lspci -n -m | awk '\
BEGIN {FS=" " ; OFS=" "; } {
ORS=" "; print "pci"; pci_progif="00";
for (i = 3; i + offset <= NF; i = i + 1) {
if ($i ~ /^[^-]/) {
if ($i ~ /\"\"/)
{ print "0000"; }
else
{ print $i;};
} else if ($i ~ /^-p/) {
pci_progif=substr($i,3,2);
}
};
ORS="\n"; print $2 pci_progif;
}' | tr -d '"' > $OUT
subsys '# PCI detection with /sys'
[ -d /sys/bus/pci/devices/ ] && \
for dev in $(ls -U /sys/bus/pci/devices/) ; do
vendor=$(cat "/sys/bus/pci/devices/$dev/vendor" | sed -ne 's/0x\([0-90-f]\{4\}\)/\1/p' -)
device=$(cat "/sys/bus/pci/devices/$dev/device" | sed -ne 's/0x\([0-90-f]\{4\}\)/\1/p' -)
svendor=$(cat "/sys/bus/pci/devices/$dev/subsystem_vendor" | sed -ne 's/0x\([0-90-f]\{4\}\)/\1/p' -)
sdevice=$(cat "/sys/bus/pci/devices/$dev/subsystem_device" | sed -ne 's/0x\([0-90-f]\{4\}\)/\1/p' -)
class=$(cat "/sys/bus/pci/devices/$dev/class" | sed -ne 's/0x\([0-90-f]\{6\}\)/\1/p' -)
found "pci $vendor $device $svendor $sdevice $class"
done
#--- USB ---#
subsys '# USB detection using /sys'
[ -d /sys/bus/usb/devices/ ] && \
for dev in $(ls -U /sys/bus/usb/devices/) ; do
vend="...."; product="...."; bcd="....";
d_class=".."; d_subcl=".."; d_prot=".."; i_class=".."; i_subcl=".."; i_prot=".."
[ -f "/sys/bus/usb/devices/$dev/idVendor" ] && vend=$(cat "/sys/bus/usb/devices/$dev/idVendor")
[ -f "/sys/bus/usb/devices/$dev/idProduct" ] && product=$(cat "/sys/bus/usb/devices/$dev/idProduct")
[ -f "/sys/bus/usb/devices/$dev/bcdDevice" ] && bcd=$(cat "/sys/bus/usb/devices/$dev/bcdDevice")
[ -f "/sys/bus/usb/devices/$dev/bDeviceClass" ] && d_class=$(cat "/sys/bus/usb/devices/$dev/bDeviceClass")
[ -f "/sys/bus/usb/devices/$dev/bDeviceSubClass" ] && d_subcl=$(cat "/sys/bus/usb/devices/$dev/bDeviceSubClass")
[ -f "/sys/bus/usb/devices/$dev/bDeviceProtocol" ] && d_prot=$(cat "/sys/bus/usb/devices/$dev/bDeviceProtocol")
[ -f "/sys/bus/usb/devices/$dev/bInterfaceClass" ] && i_class=$(cat "/sys/bus/usb/devices/$dev/bInterfaceClass")
[ -f "/sys/bus/usb/devices/$dev/bInterfaceSubClass" ] && i_subcl=$(cat "/sys/bus/usb/devices/$dev/bInterfaceSubClass")
[ -f "/sys/bus/usb/devices/$dev/bInterfaceProtocol" ] && i_prot=$(cat "/sys/bus/usb/devices/$dev/bInterfaceProtocol")
found "usb $vend $product $d_class$d_subcl$d_prot $i_class$i_subcl$i_prot $bcd"
done
#-- IEEE1394 -- #
subsys '# IEEE1394 detection with /sys'
[ -d /sys/bus/ieee1394/devices/ ] && \
for dev in $(ls -U /sys/bus/ieee1394/devices/) ; do
if [ -f "/sys/bus/ieee1394/devices/$dev/vendor_id" ] ; then
vend=$(cat "/sys/bus/ieee1394/devices/$dev/vendor_id" | tail -c +3 -)
if ls -U "/sys/bus/ieee1394/devices/$dev" | grep -sqe "$dev-" - ; then
for sub in $(ls -U "/sys/bus/ieee1394/devices/$dev/$dev-*") ; do
spec=$(cat "/sys/bus/ieee1394/devices/$dev/$sub/specifier_id" | tail -c +3 -)
vers=$(cat "/sys/bus/ieee1394/devices/$dev/$sub/version" | tail -c +3 -)
found "ieee1394 $vend xxxxxx $spec $vers"
done
else
found "ieee1394 $vend xxxxxx xxxxxx xxxxxx"
fi
fi
done
#
#-- ACPI -- #
subsys '# ACPI detection with /sys'
[ -d /sys/bus/acpi/devices/ ] && \
for dev in $(ls -U /sys/bus/acpi/devices/) ; do
if [ -f "/sys/bus/acpi/devices/$dev/hid" ] ; then
id=$(cat "/sys/bus/acpi/devices/$dev/hid")
found "acpi $id"
fi
done
#-- PNP -- #
subsys '# PNP detection with /sys'
[ -d /sys/bus/pnp/devices/ ] && \
for dev in $(ls -U /sys/bus/pnp/devices/) ; do
id=$(cat "/sys/bus/pnp/devices/$dev/id" | tr '\n' ' ' )
found "pnp $id"
done
#-- serio -- #
subsys '# serio detection with /sys'
[ -d /sys/bus/serio/devices/ ] && \
for dev in $(ls -U /sys/bus/serio/devices/) ; do
typ=$(cat "/sys/bus/serio/devices/$dev/id/type")
proto=$(cat "/sys/bus/serio/devices/$dev/id/proto")
id=$(cat "/sys/bus/serio/devices/$dev/id/id")
extra=$(cat "/sys/bus/serio/devices/$dev/id/extra")
found "serio $typ $proto $id $extra"
done
#-- I2C -- #
subsys '# I2C detection with /sys'
[ -d /sys/bus/i2c/devices/ ] && \
for dev in $(ls -U /sys/bus/i2c/devices/) ; do
id=$(cat "/sys/bus/i2c/devices/$dev/name")
found "i2c $id"
done
#-- platform -- #
subsys '# platform detection with /sys'
[ -d /sys/bus/platform/devices/ ] && \
for dev in $(ls -U /sys/bus/platform/devices/) ; do
found $(cat /sys/bus/platform/devices/$dev/modalias | sed -ne 's/^platform:\(.*\)$/platform "\1"/p' - )
done
#--- FS ---#
subsys '# FS detection using mount'
for fs in $(mount | sed -ne 's/^.*type \([^ ]*\).*$/\1/p' - | sort -u ) ; do
found "fs $fs"
done
subsys '# FS detection using /etc/fstab'
[ -f /etc/fstab ] && \
for fs in $(grep -v '^#' /etc/fstab | sed -nre 's/^[^[:space:]]+[[:space:]]+[^[:space:]]+[[:space:]]+([^[:space:]]+)[[:space:]]+.*$/\1/p' - | sort -u ) ; do
found "fs $fs"
done
#--- kernel modules ---#
subsys '# kernel modules detection using lsmod and /proc/modules'
for module in $( (cat /proc/modules; /sbin/lsmod) | tail -n +2 | cut -d " " -f 1 | sort -u ) ; do
found "module $module"
done
#--- Check files ---#
if [ ! -d /proc ]; then
comment_err '*** Warning: /proc not found!'
fi
if [ ! -d /sys ]; then
comment_err '*** Warning: /sys not found!'
fi
#--- Others ---#
subsys "# Other informations"
found "kernel $(uname -s) $(uname -r)"
found "arch $(uname -m) $(uname -p) $(uname -m)"
[ -f /proc/modules ] && found "config MODULES"
grep -sqe '^/' /proc/swaps && found "config SWAP"
ipcs -a | grep -sqe '^0x' - && found SYSVIPC