#!/bin/sh

basename=`basename "$0"`

if [ x`whoami` != "xroot" ]; then
	echo "$basename: Warning: This script should be run as root." >&2
fi

if [ x`which lshw` == "x" ]; then
	echo "$basename: Error: lshw not found, probably not installed. Exiting." >&2
	exit 1
fi

IFS_ORIGINAL="$IFS"
IFS_NEWLINE="
"

status=0

IFS="$IFS_NEWLINE"
for i in `lshw -class disk 2>/dev/null`; do
	IFS="$IFS_ORIGINAL"
	case "$status" in
		0)
			echo "$i" | grep -q '*-disk'
			if [ $? == 0 ]; then
				logical_name="?"
				serial="?"
				status=1
			fi
		;;
		
		1)
			echo "$i" | grep -q 'logical name:'
			if [ $? == 0 ]; then
				logical_name="`echo $i | cut -d : -f 2 | cut -d ' ' -f 2`"
				continue
			fi

			echo "$i" | grep -q 'serial:'
			if [ $? == 0 ]; then
				serial="`echo $i | cut -d : -f 2 | cut -d ' ' -f 2`"
				continue
			fi

			echo "$i" | grep -q '*-'
			if [ $? == 0 ]; then
				status=0
				echo "$logical_name $serial"
				continue
			fi
		;;
	esac
done

if [ $status == 1 ]; then
	status=0
	echo "$logical_name $serial"
fi

exit 0

