#! /bin/sh
#
#	0.1: Oct. 22, 2002 by Dai ISHIJIMA
#	0.2: May   1, 2004
#


# erase method
msg="write '0'"
flag='-z'
case "$1" in
	-z)
		msg="write '0'"
		flag='-z'
		shift
		;;
	-f)
		msg="write '1'"
		flag='-f'
		shift
		;;
	-r)
		msg="write random data"
		flag='-r'
		shift
		;;
esac


# select disk
disk=/dev/rad0
case "$1" in
	/dev/r*[0-9]) disk="$1" ;;
esac

# calculate disk size
if ! total=`expr "$NCYLS" '*' "$NHEAD" '*' "$NSECS" '*' 512 2>/dev/null`; then
	echo ''
	echo '**** no disk information'
	exit 1
fi
kb=`expr $total / 1024`
mb=`expr $kb / 1024`
gb=`expr $mb / 1024`

# blocksize set to 1 mega bytes
obs=`expr 1024 '*' 1024`
max=`expr $total / $obs`
ibs=1024

# erase 32Mbytes at a job
icnt=32768
ocnt=32

echo ''
echo "Erase ($msg) ENTIRE disk '$disk'."
echo -n 'Ok? [y/n] '

read x
case $x in
	y) ;;
	*) echo 'Aborted'; exit 1;;
esac

echo ''
echo "Erase ($msg) $total [bytes] ($kb [kbytes], $mb [Mbytes], $gb [Gbytes])"
echo -n 'Are you sure? [y/n] '

read x
case $x in
	y) ;;
	*) echo 'Aborted'; exit 1;;
esac

echo ''
echo -n 'Really? [yes/no] '

read x
case $x in
	yes) ;;
	*) echo 'Aborted'; exit 1;;
esac

#
skip=0

#
echo ''

echo ''; echo ''; echo ''; echo ''; echo '';
echo ''; echo ''; echo ''; echo ''; echo '';
echo -n '[10A'
echo -n '7'
echo "0 / $max = 0 % done."
echo '0....1....2....3....4....5....6....7....8....9....'
while [ $skip -le $max ]; do
	echo -n '8'
	echo -n '7'
	p=`expr 100 '*' $skip / $max`
	echo "$skip / $max = $p % done. "
	q=`expr $p / 2`
	i=0
	while [ $i -lt $q ]; do
		echo -n '#'
		i=`expr $i + 1`
	done
	echo ''; echo ''
	echo "stuff $flag | dd ibs=$ibs obs=$obs seek=$skip count=$icnt of=$disk"
	stuff $flag | dd ibs=$ibs obs=$obs seek=$skip count=$icnt of=$disk
	echo ''
	skip=`expr $skip + $ocnt`
done

p=`expr 100 '*' $skip / $max`
echo -n '8'
echo "$skip / $max = $p % done. "
echo '##################################################'
echo ''; echo ''; echo ''; echo ''; echo ''
echo ''; echo ''; echo ''; echo ''; echo ''
echo 'all done.'
echo ''
echo -n 'Press ENTER to return menu...'
read x

exit 0
