#! /bin/sh

master=/dev/rad0
slave=/dev/rad1
disk=$slave
dname=slave

#
# total disksize 20e9 =~ 19 * 1024 megabytes
# total disksize: 39560c/16h/63s = 39876480 [blocks] = 20416757760 [bytes]
#	= 19938240 [kbytes] = 19470.9375 [Mbytes] = 19.01458740234375 [Gbytes]
#
total=`expr 39560 '*' 16 '*' 63 '*' 512`

# blocksize set to 1 mega bytes
obs=`expr 1024 '*' 1024`

# 
max=`expr $total / $obs`

# erase 32Mbytes at a job
count=32

########################################################################

case x$1 in
	xad0) disk=/dev/rad0; dname=master ;;
	xad1) disk=/dev/rad1; dname=slave ;;
esac

echo ''
echo "Erase ENTIRE disk of primary-${dname}."
echo -n 'Ok? [y/n] '

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

kb=`expr $total / 1024`
mb=`expr $kb / 1024`
gb=`expr $mb / 1024`

echo ''
echo "Erase $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

#
p=0
#
echo ''; echo ''; echo ''; echo ''; echo '';
echo ''; echo ''; echo ''; echo ''; echo '';

while [ $skip -le $max ]; do
	p=`expr 100 '*' $skip / $max`
	echo '[15;1H'
	echo "$skip / $max = $p % done"
	echo ''
	echo dd if=/dev/zero bs=$obs seek=$skip count=$count of=$disk
	dd if=/dev/zero bs=$obs seek=$skip count=$count of=$disk
	echo ''
	skip=`expr $skip + $count`
done

p=`expr 100 '*' $skip / $max`
echo '[15;1H'
echo "$skip / $max = $p % done"
echo ''; echo ''; echo ''; echo ''; echo ''
echo 'all done.'

read x

exit 0

