#! /bin/sh

master=/dev/rad0
slave=/dev/rad1
s=master
d=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) master=/dev/rad0; slave=/dev/rad1; s=master; d=slave ;;
	xad1) master=/dev/rad1; slave=/dev/rad0; s=slave; d=master ;;
esac

echo ''
echo "Copy whole disk of primary $s to primary ${d}."
echo -n 'Ok? [y/n] '

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

echo ''
echo "Are you sure that source disk is connected as primary $s"
echo "and destination disk is connected as primary ${d}?"
echo -n 'Ok? [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 bs=$obs skip=$skip seek=$skip count=$count if=$master of=$slave
	dd bs=$obs skip=$skip seek=$skip count=$count if=$master of=$slave
	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





