#!/bin/sh

# savehome  - saves home directory to

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



if [ -f /etc/tux/config/home ]
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

[ -d /usr/local/tmp ] || mkdir -p /usr/local/tmp 

cd /
tar cf - home | gzip -f > /usr/local/tmp/$home.tgz
echo "Saving home directory to $USER@$HOST via $PROTO"

cd /usr/local/tmp

if [ "$PROTO" = "ssh" ]
then
	scp $home.tgz $USER@$HOST:~
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 -T $home.tgz ftp://$HOST

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

		ftp $HOST

	fi
fi

if [ "$PROTO" = "fixed" ]
then
	if mount -t $PROTO $HOST /mnt
	then
		[ "$USER" ] && cd /mnt/$USER
		cp /usr/local/tmp/$home.tgz .
		cd /
		umount /mnt
	fi
fi

if [ "$PROTO" = "floppy" ]
then 
	if mount -t vfat /dev/fd0 /mnt
	then
		cp /usr/local/tmp/$home.tgz /mnt
		cd /
		umount /mnt
	else
		echo "Unable to mount floppy"
	fi
fi
