#!/bin/sh

# say who we are and what we're doing
#
echo "Uninstalling the TeraGrid Client Toolkit."

# make sure the working dir is inside the install directory
#
if ! [ -x uninstall-teragrid-client ]
then
	echo "ERROR: Please run this uninstaller from" \
	     "inside the install directory."
	exit 1
fi

# check for list of files that we shouldn't delete
# (these are the files that came as part of the install tarball)
#
if ! [ -f tarball-file-list ]
then
	echo "No installation detected; exiting."
	exit 0
fi

# remove everything except what's in tarball-file-list
# (but don't delete tarball-file-list itself yet)
#
for FILE in `ls | cat - tarball-file-list | sort | uniq -u`
do
	if [ $FILE != tarball-file-list ]
	then
		if rm -rf $FILE
		then
			echo "* Removed $FILE."
		else
			echo "* Error removing $FILE."
			ERROR=1
		fi
	fi
done
if [ "$ERROR" = 1 ]
then
	echo "ERROR: Could not fully uninstall the toolkit."
	exit 1
fi

# lastly, delete tarball-file-list
#
if rm tarball-file-list
then
	echo "* Removed tarball-file-list."
else
	echo "* Error removing tarball-file-list."
	echo "ERROR: Could not fully uninstall the toolkit."
	exit 1
fi

# encouraging message!
#
echo "TeraGrid Client Toolkit successfully uninstalled."
