Minix1.5/amoeba/util/rcp

: Copy a file from any machine to any other machine.
usage="Usage: $0 [machine!]from-file [machine!]to-file"
PATH=/usr/local:/bin:/usr/bin
CDPATH=
case $# in
2)	:
	;;
*)	echo "$usage" 1>&2
	exit 1
esac
from=$1 to=$2
case $from in
*!*)	IFS="!"
	set $from
	case $# in
	2)	from_mach=$1 from_file=$2 IFS=" "
		;;
	*)	echo "$usage" 1>&2
		exit 1
	esac
	;;
*)	from_file=$from
esac
case "$from_file" in
"")	echo "$usage" 1>&2
	exit 1
esac
case $to in
*!*)	IFS="!"
	set $to
	case $# in
	2)	to_mach=$1 to_file=$2 IFS=" "
		;;
	*)	echo "$usage" 1>&2
		exit 1
	esac
	;;
*)	to_file=$to
esac
case "$to_file" in
"")	echo "$usage" 1>&2
	exit 1
esac
case "$from_mach" in
"$to_mach")
	: machines equal
	case "$to_mach" in
	"")	: local
		cp "$from_file" "$to_file"
		;;
	*)	: remote
		rsh "$to_mach" "cp $from_file $to_file"
		;;
	esac
	;;
*)	: machines not equal
	case "$to_mach" in
	"")	: to local
		if test -d "$to_file"
		then	rsh -e "$from_mach" "cat $from_file" >"$to_file/`basename $from_file`"
		else	rsh -e "$from_mach" "cat $from_file" >"$to_file"
		fi
		;;
	*)	: to remote
		case "$from_mach" in
		"")	: from local
			rsh -i "$to_mach" "if test -d $to_file; then cat >$to_file/`basename $from_file`; else cat >$to_file; fi" <"$from_file"
			;;
		*)	: from remote
			rsh -e "$from_mach" "cat $from_file" | rsh -i "$to_mach" "if test -d $to_file; then cat >$to_file/`basename $from_file`; else cat >$to_file; fi"
			;;
		esac
		;;
	esac
	;;
esac