#!/bin/sh
#
# get -- get files or the current directory, to FARMACHINE by ssh
#
[ -n "$echo" ] && set -x

: ${FARMACHINE='eustis.eecs.ucf.edu'}
: ${ME='gleavens'}
USAGE='get-from-eustis [file2] ...'

# no options allowed
case "$1" in
-*)
	echo "$USAGE" >&2
	exit 2
	;;
esac

STATUS=0

# get part of directory name below $HOME or $ALTHOME
fulldir=`pwd`

case "$fulldir" in
$HOME|$CYGDRIVEHOME)
	below=.
	if test "$#" -eq 0
	then
	    echo "ERROR: can't get everything in $HOME" >&2
	    exit 1
	fi
	;;
*)
	below=`expr $fulldir : $HOME/'\(.*\)'`
	;;
esac

case "$below" in
0|'')
   below=`expr $fulldir : $CYGDRIVEHOME/'\(.*\)'`
   ;;
esac

awaybelow="$below"

case "$below" in
0|'')
	echo "can't get from $fulldir, not under $HOME" >&2
	exit 1
	;;
bin|bin/Obsolete|bat)
   awaybelow="WWW/Windows/$below"
   if test $# -le 0
   then
       echo "can't update all of $below" >&2
       exit 2
   fi
   ;;
*)
   ;;
esac

echo "getting from ~/${awaybelow} on $FARMACHINE"

if test $# -gt 0
then
    for f
    do
	scp -p "$ME@$FARMACHINE:${awaybelow}/$f" . || STATUS=1
	chmod u+rwx,go-w "$f"
    done
fi

exit $STATUS

