#!/bin/bash
# Copyright 2008,2009 TJ <ubuntu@tjworld.net>
# Licensed on the terms of the GNU GPL v3
# see /usr/share/common-licenses/GPL-3
# Get the make and model
if [ "x$1" != "x-f" ]; then 
 if [ ! $(which dmidecode)  ]; then
  # need to install the package
  echo "dmidecode is needed to determine the system make and model"
  echo "please install it and then re-run this script"
  echo "  sudo apt-get install dmidecode"
  echo "To run without dmidecode use '$0 -f'"
  exit 1
 else
  echo "Need privileges to execute dmidecode..."
  echo "Make: $(sudo /usr/sbin/dmidecode -s system-manufacturer)"
  echo "Model: $(sudo /usr/sbin/dmidecode -s system-product-name)"
  echo "BIOS: $(sudo  /usr/sbin/dmidecode -s bios-version)"
 fi
fi
# Read the PCI device list
lspci -nn | while read device; do
 DEVICEID=$(echo $device | sed 's/.* \[\(.*\):\(.*\)\].*/\1:\2/')
 DEVICENAME="$(echo $device |  sed 's/^[0-9a-f:\.]\+ \(.*\) \[.*:.*\].*/\1/')"
 VENDOR=${DEVICEID%%:*}
 DEVICE=${DEVICEID##*:}
 KERNEL_MODULE="$(lspci -vvnn -d$VENDOR:$DEVICE | sed -n '/Kernel modules/s/^.*modules: //p')"
 [ -z "$KERNEL_MODULE" ] && KERNEL_MODULE="$(lspci -vvnn -d$VENDOR:$DEVICE | sed -n '/in use/s/^.*use: //p')"
 [ -z "$KERNEL_MODULE" ] && KERNEL_MODULE="$(sed -n -e "/$VENDOR.*$DEVICE/ {s/\([[:alnum:]_-]*\).*/\1/p;q;}" /lib/modules/`uname -r`/modules.pcimap)"
 [ -z "$KERNEL_MODULE" ] && KERNEL_MODULE="UNKNOWN"
 XORG_LIBRARY=$(expr match "$(grep -i $VENDOR.*$DEVICE /usr/share/xserver-xorg/pci/*)" '.*/pci/\(.*\)\..*'  )
 [ ! -z "$XORG_LIBRARY" ] && XORG_LIBRARY="(xorg=$XORG_LIBRARY)"
 echo "PCI: $DEVICEID $KERNEL_MODULE $XORG_LIBRARY = $DEVICENAME"
done
# Read the USB device list
lsusb | while read device; do
 DEVICEID="$(echo $device | sed -n 's/^.*ID \([[:xdigit:]:]\{9\}\).*/\1/p')"
 DEVICENAME="$(echo $device | sed -n 's/^.*ID [[:xdigit:]:]\{9\} \(.*\)$/\1/p')"
 VENDOR=${DEVICEID%%:*}
 DEVICE=${DEVICEID##*:}
 KERNEL_MODULE="$(sed -n -e "/$VENDOR.*$DEVICE/ {s/\([[:alnum:]_-]*\).*/\1/p;q;}" /lib/modules/`uname -r`/modules.usbmap)"
 echo "USB: $DEVICEID $KERNEL_MODULE = $DEVICENAME"
done



syntax highlighted by Code2HTML, v. 0.9.1