#!/bin/sh

echo "XSatellite install script v0.1"

echo
echo "--------------------------------------------------------------------------------"
bflag=1
while test $bflag -eq 1
do
	echo "Where do you wish to install XSatellite ?"
        echo -n "[/usr/local/xsat] :"
	read D

	if test "$D" = "" ; then 
		D="/usr/local/xsat"
	fi

	if [ -d $D ]; then
		echo "Dir [$D] allready exist."

		flag=1
		while test $flag -eq 1
		do
			echo -n "Install anyway ? [y/N] "
			read A
			if test "$A" = "y" -o "$A" = "Y" ; then 
				flag=0
				bflag=0
				fi
			if test "$A" = "n" -o "$A" = "N" ; then 
				flag=0
				bflag=1
			fi
		done

	else
		echo "Dir [$D] not found"

		flag=1
		while test $flag -eq 1
		do
			echo -n "Do you wish to create it ? [y/N] "
			read A
			if test "$A" = "y" -o "$A" = "Y" ; then 
				flag=0
				bflag=0
                                mkdir -p $D
				fi
			if test "$A" = "n" -o "$A" = "N" ; then 
				flag=0
				bflag=1
			fi
		done

	fi
done
INSTALLDIR=$D



echo
echo "--------------------------------------------------------------------------------"
flag=1
while test $flag -eq 1
do
echo -n "Ok to install XSatellite ? [y/N] :"
read A
if test "$A" = "y" -o "$A" = "Y" ; then 
flag=0
fi
if test "$A" = "n" -o "$A" = "N" ; then 
flag=0
fi
done
GO=$A


#------------------------------------------------------------------------------------

if test "$GO" = "y" -o "$GO" = "Y" ; then 
echo "Installing XSatellite in $INSTALLDIR"
else
echo "Aborting installation!"
fi


mkdir -p $INSTALLDIR/gif
mkdir -p $INSTALLDIR/Satellite
mkdir -p $INSTALLDIR/wav
mkdir -p $INSTALLDIR/config
mkdir -p $INSTALLDIR/tcl

cp ./gif/* $INSTALLDIR/gif
cp ./Satellite/* $INSTALLDIR/Satellite 
cp ./wav/* $INSTALLDIR/wav
cp ./config/* $INSTALLDIR/config
cp ./tcl/* $INSTALLDIR/tcl

cp ./xsatellite.tcl $INSTALLDIR
cp ./COPYING $INSTALLDIR
cp ./README $INSTALLDIR
cp ./CHANGES $INSTALLDIR


echo "#!/bin/sh" >/usr/bin/xsatellite 
echo -e "cd $INSTALLDIR">>/usr/bin/xsatellite
echo -e "wish xsatellite.tcl">>/usr/bin/xsatellite
chmod 777 /usr/bin/xsatellite       

echo "XSatellite was successfully installed in $INSTALLDIR"
echo "If wish is not in path edit the file /usr/bin/xsatellite"
echo ""
echo "To start the program type xsatellite and hit enter"
