Howto/MatchDeviceIDtoDriver: device2driver

File device2driver, 2.0 KB (added by tj, 9 years ago)

device2driver shell script

Line 
1#!/bin/bash
2# Copyright 2008,2009 TJ <ubuntu@tjworld.net>
3# Licensed on the terms of the GNU GPL v3
4# see /usr/share/common-licenses/GPL-3
5
6# Get the make and model
7if [ "x$1" != "x-f" ]; then
8 if [ ! $(which dmidecode)  ]; then
9  # need to install the package
10  echo "dmidecode is needed to determine the system make and model"
11  echo "please install it and then re-run this script"
12  echo "  sudo apt-get install dmidecode"
13  echo "To run without dmidecode use '$0 -f'"
14  exit 1
15 else
16  echo "Need privileges to execute dmidecode..."
17  echo "Make: $(sudo /usr/sbin/dmidecode -s system-manufacturer)"
18  echo "Model: $(sudo /usr/sbin/dmidecode -s system-product-name)"
19  echo "BIOS: $(sudo  /usr/sbin/dmidecode -s bios-version)"
20 fi
21fi
22
23# Read the PCI device list
24lspci -nn | while read device; do
25 DEVICEID=$(echo $device | sed 's/.* \[\(.*\):\(.*\)\].*/\1:\2/')
26 DEVICENAME="$(echo $device |  sed 's/^[0-9a-f:\.]\+ \(.*\) \[.*:.*\].*/\1/')"
27 VENDOR=${DEVICEID%%:*}
28 DEVICE=${DEVICEID##*:}
29 KERNEL_MODULE="$(lspci -vvnn -d$VENDOR:$DEVICE | sed -n '/Kernel modules/s/^.*modules: //p')"
30 [ -z "$KERNEL_MODULE" ] && KERNEL_MODULE="$(lspci -vvnn -d$VENDOR:$DEVICE | sed -n '/in use/s/^.*use: //p')"
31 [ -z "$KERNEL_MODULE" ] && KERNEL_MODULE="$(sed -n -e "/$VENDOR.*$DEVICE/ {s/\([[:alnum:]_-]*\).*/\1/p;q;}" /lib/modules/`uname -r`/modules.pcimap)"
32 [ -z "$KERNEL_MODULE" ] && KERNEL_MODULE="UNKNOWN"
33 XORG_LIBRARY=$(expr match "$(grep -i $VENDOR.*$DEVICE /usr/share/xserver-xorg/pci/*)" '.*/pci/\(.*\)\..*'  )
34 [ ! -z "$XORG_LIBRARY" ] && XORG_LIBRARY="(xorg=$XORG_LIBRARY)"
35 echo "PCI: $DEVICEID $KERNEL_MODULE $XORG_LIBRARY = $DEVICENAME"
36done
37
38# Read the USB device list
39lsusb | while read device; do
40 DEVICEID="$(echo $device | sed -n 's/^.*ID \([[:xdigit:]:]\{9\}\).*/\1/p')"
41 DEVICENAME="$(echo $device | sed -n 's/^.*ID [[:xdigit:]:]\{9\} \(.*\)$/\1/p')"
42 VENDOR=${DEVICEID%%:*}
43 DEVICE=${DEVICEID##*:}
44 KERNEL_MODULE="$(sed -n -e "/$VENDOR.*$DEVICE/ {s/\([[:alnum:]_-]*\).*/\1/p;q;}" /lib/modules/`uname -r`/modules.usbmap)"
45 echo "USB: $DEVICEID $KERNEL_MODULE = $DEVICENAME"
46done
47