#!/bin/sh -e
#
# Report the detected HW. Note that this needs to run both inside d-i
# and in a regular debian system, as well as behaving robustly if commands
# are missing or broken.

addinfo () {
	sed "s%^%$1: %"
}

addfile () {
	if [ -r "$1" ]; then
		cat "$1" | addinfo "$1"
	fi
}

uname -a 2>&1 | addinfo "uname -a"

if type lspci >/dev/null 2>&1; then
	lspci -knn 2>&1 | addinfo "lspci -knn"
	#lspci -vnn 2>&1 | addinfo "lspci -vnn"
else
	addfile /proc/pci
	addfile /proc/bus/pci/devices
fi

if type prtconf >/dev/null 2>&1 ; then
	prtconf 2>&1 | addinfo "prtconf"
fi

lsmod 2>&1 | addinfo lsmod
df 2>&1 | addinfo df
free 2>&1 | addinfo free

if type pccardctl >/dev/null 2>&1; then
	pccardctl status 2>&1 | addinfo "pccardctl status"
	pccardctl ident 2>&1 | addinfo "pccardctl ident"
fi

if type dmraid >/dev/null 2>&1; then
	dmraid -s 2>&1 | addinfo "dmraid -s"
	dmraid -r 2>&1 | addinfo "dmraid -r"
	if type dmsetup >/dev/null 2>&1; then
		dmsetup table 2>&1 | addinfo "dmsetup table"
	fi
fi

for file in cmdline cpuinfo ioports iomem interrupts meminfo \
	bus/usb/devices bus/input/devices; do
	addfile /proc/$file
done
if type dmidecode >/dev/null 2>&1; then
	dmidecode 2>&1 | addinfo dmidecode
fi

if [ "$DEBIAN_FRONTEND" = gtk ]; then
	addfile /proc/fb
	addfile /etc/directfbrc
	dfbinfo=$(ls /usr/lib/directfb-*/bin/dfbinfo 2>/dev/null || true)
	if [ -x "$dfbinfo" ]; then
		$dfbinfo 2>&1 | addinfo dfbinfo
	fi
fi
