#!/bin/sh

# Set default values
APPDIR=${APPDIR:-..}
VERBOSE=${VERBOSE:-0}

. ${APPDIR}/common.subr

sect "System information"

if check_privs /dev/mem; then
# Check whether dmidecode tool is available
if which -s dmidecode; then
	dmidecode -t system | sed -En 's/^[[:space:]]+//; /Manufacturer|Product/p'

	if is_verbose 1; then
		echo
		dmidecode -t system | sed -En 's/^[[:space:]]+//; /Serial|UUID/p'
	fi

	echo
	info "Run \`dmidecode -t system\` to see further information."

	echo
	subsect "Base board information"

	dmidecode -t baseboard | sed -En 's/^[[:space:]]+//; /Manufacturer|Product/p'

	if is_verbose 1; then
		echo
		dmidecode -t baseboard | sed -En 's/^[[:space:]]+//; /Version|Serial/p'
	fi

	echo
	info "Run \`dmidecode -t baseboard\` to see further information."
else
	# Advice to install it
	warn "You will need to install the sysutils/dmidecode port in order to obtain this information."
fi
fi

if check_privs /var/run/dmesg.boot; then
	if grep -q "^acd[[:digit:]]" /var/run/dmesg.boot; then
		subsect "\nCD/DVD-ROM:"
		grep "^acd[[:digit:]]" /var/run/dmesg.boot | grep -iv "attempt\|failure"
	fi

	if grep -q "^fd[[:digit:]]" /var/run/dmesg.boot; then
		subsect "\nFloppy disk:"
		grep "^fd[[:digit:]]" /var/run/dmesg.boot
	fi
fi	

subsect "\nGraphic card information:"
getpciconf vgapci "vendor device"
info "Check pciconf(8) for more information."

if pciconf -l | grep -q "^none[0-9]"; then
	subsect "\nPCI devices with no driver attached:"
	pciconf -l | grep "^none[0-9]"
fi

exit 0
