#!/bin/sh
#
# detect-config.opts - Detect config.opts settings using dmidecode
#

msg()
{
    echo "$@" >&2
}

dmi_get()
{
    cat $dmidata | sed -n "/$1\$/,\$p" | sed '/^Handle/,$d' | tr -d '\t' \
	| tail +2 | grep "^$2" | cut -d: -f2 \
	| sed 's/^ *\([^ ].*[^ ]\) *$/\1/'
}

if ! [ -x /usr/sbin/dmidecode ]; then
    msg "Not detecting special resource options (dmidecode not available)"
    exit 1
fi

if [ -x /bin/mktemp ]; then
    dmidata=$(mktemp)
else
    dmidata=/etc/pcmcia/dmidata
fi

if ! dmidecode >$dmidata; then
    msg "Not detecting special resource options (dmidecode failed)"
    rm -f $dmidata
    exit 1
fi

resources=''

manufacturer="$(dmi_get 'System Information' 'Manufacturer')"
product="$(dmi_get 'System Information' 'Product Name')"
version="$(dmi_get 'System Information' 'Version')"

compid="$manufacturer -- $product"
if [ -n "$version" ] && [ "$version" != "Not Available" ] &&
    [ "$version" != "Not Specified" ]; then
    compid="$compid -- $version"
fi

msg "Computer: $compid"

case "$manufacturer" in
    Dell*)
	case "$product" in
	    "Inspiron 8"*|"Latitude D800"*|"Latitude D505"*|\
	    "Latitude D600"*)
		resources="exclude port 0x800-0x8ff"
		;;
	esac
	;;
esac

if [ -z "$resources" ]; then
    msg "No special resource options detected."
fi

echo "$resources"

rm -f $dmidata
