#! /usr/bin/sh
#
#ident	"@(#)scp.sh	1.8	05/06/08 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# by Mark F. Logan
# Modified by Andrew McCarthy

if [ $# -ne 1 ]
then
	echo "Usage: $0 dest-machine"
	exit 1
fi

echo "Runtime: $RUNTIME seconds."
sleep $RUNTIME &
sleepid=$!
iter=1

echo "Changing local directory to /tmp."
cd /tmp

local=`hostname`
version=`/usr/bin/uname -r|awk -F. '{print $2}'`

while [ -d /proc/$sleepid ]
do
	date
	if [ $version -lt 10 ]
	then
		rcp /kernel/genunix $1:/export/home/tmp/genunix.$local.$$
		rcp $1:/export/home/tmp/genunix.$local.$$ genunix.$$
		if cmp genunix.$$ /kernel/genunix
		then
			rm genunix.$$
			rcp /etc/motd $1:/export/home/tmp/genunix.$local.$$
		else
			echo "!ERROR: CMP failed on iteration $iter."
			exit $?
		fi
	else
		scp /kernel/genunix $1:/export/home/tmp/genunix.$local.$$
		scp $1:/export/home/tmp/genunix.$local.$$ genunix.$$
		if cmp genunix.$$ /kernel/genunix
		then
			rm genunix.$$
			scp /etc/motd $1:/export/home/tmp/genunix.$local.$$
		else
			echo "!ERROR: CMP failed on iteration $iter."
			exit $?
		fi
	fi
	iter=`expr $iter + 1`
	sleep 1
done

echo "!PASS: Completed $iter copies successfully."
