#!/bin/sh
# $Id: showdisk 1.2 Thu, 17 Dec 1998 23:47:52 +0100 hlovdal $
# In order to not be dependent on external programs the "while read"
# construct is used at the end. 

PATH=$PATH:/sbin:/usr/sbin:/mnt/sbin

check_fdisk()
{
	oldIFS=$IFS
	IFS=: 
	fdisk="not found"
	for i in $PATH
	do
		if [ -x $i/fdisk -a ! -d $i/fdisk ]
		then
			fdisk=$i/fdisk
			break
		fi
	done
	IFS=$oldIFS
	if [ "$fdisk" = "not found" ]
	then
		echo "$0: Unable to find the fdisk program" 1>&2
		exit 1
	fi
}


check_fdisk


if [ -w /dev/null ]
then
	exec 6> /dev/null
else
	exec 6>&2
fi

echo ""		# DON'T DELETE THIS LINE
#	The following backquote expression may trigger a bug in ash-0.2,
#	and it is therefore vital that something is written to stdout
#	in advance, or else the shell dies with a segmentation fault... :(

if [ "`$fdisk -l 2>&6`" = "" ]
then
	echo "$0: Error: no device files or insufficient privileges to run fdisk" 1>&2
	exit 1
fi

# shell function semi equivalent to "echo $1 | cut -d: -f1"
echodisk()
{
	oldIFS=$IFS
	IFS=:
	set $1
	echo "	" $1
	IFS=$oldIFS
}

echo "Your system has the following disks:"
echo ""
$fdisk -l 2>&6 | while read thefirstword diskname therest
		do
			if [ "$thefirstword" = "Disk" ]
			then
				echodisk $diskname
			fi
		done
echo ""

