#!/bin/sh
#
# Author: Petter Reinholdtsen
# Date:   2005-03-28
#
# Script to process the output of '(lspci;lspci -n)|sort', and report
# the entries present and missing.

usage() {
    echo "Usage: $0 <lspci-report>"
    echo
    echo "The content of <lspci-report> is a file generated using"
    echo "  (lspci;lspci -n) | sort > lspci-report"
}

if [ -z "$1" ] ; then
    usage
    exit 1
fi

report=$1

lsts="pci.lst pci-26.lst"
lsts="pci.lst"

for id in `sed 's/Class //' < $report | awk '/: ....:..../ { print $3 }'`; do
    if [ -z "$id" ] ; then
	echo "error: Unable to find PCI IDs"
	exit 1
    fi
    shortid=`echo $id | cut -c1-4,6-`
    for lst in $lsts; do 
	if ! grep $shortid $lst ; then
	    echo "PCI ID $id missing in $lst:"
	    busid=`awk "/ $id/ { print \\\$1 }" < $report`
#	echo "Bus id: $busid"
	    grep "$busid" $report | tail -n 1
	fi
    done
done
