#!/bin/sh

if [ "$1" ]
then
	home=$1
else
	home="home"
fi

homeline=`cat /etc/tux/config/home`

if [ "$homeline" ]
then
	PROTO=`cut -d':' -f1 /etc/tux/config/home`
	HOST=`cut -d':' -f2 /etc/tux/config/home`
	USER=`cut -d':' -f3 /etc/tux/config/home`
else
	echo -n "ftp or ssh: "
	read PROTO
	echo -n "Host: "
	read HOST
	echo -n "User: "
	read USER
	echo $PROTO:$HOST:$USER > /etc/tux/config/home
fi


echo "Retrieving home directory from $USER@$HOST via $PROTO"

if [ $PROTO = "ssh" ]
then
	scp $USER@$HOST:~/$home.tgz / 
fi

if [ $PROTO = "ftp" ]
then
	echo "Using FTP to transfor $home.tgz -- your passwords are sniffable"

	if [ -x /usr/bin/curl ]
	then
		curl -u $USER ftp://$HOST/$home.tgz > /$home.tgz

	else
		echo "Curl is not installed.  You will have to login with your" 
                echo "username and upload $home.tgz manually"

		ftp $HOST

	fi
fi

cd /
echo
echo "Uncompressing archive..."
gunzip -c $home.tgz | tar xvf -
rm /$home.tgz 2> /dev/null

 



