cd ..
if [ -f "setup.bash" ]; then
	#This is Greenstone 2
	. ./setup.bash > /dev/null
	SEARCH4J_EXECUTABLE=$GSDLHOME/bin/$GSDLOS/search4j

elif [ -f "gs2build/setup.bash" ]; then
	#This is Greenstone 3
#	. ./gs2build/setup.bash > /dev/null
	. ./gs3-setup.sh > /dev/null
	SEARCH4J_EXECUTABLE=./bin/search4j

else
	echo "Couldn't find setup.bash. Either this script has not been run from the directory it resides in, or this copy of Greenstone appears to be corrupt."
	echo "To manually uninstall, please delete the entire Greenstone home folder."
	exit
fi

if [ "$GSDLOS" = "linux" ]; then
	"$SEARCH4J_EXECUTABLE" -p ./packages/jre -l ./uninstall/uninst.jar
elif [ "$GSDLOS" = "darwin" ]; then
	"$SEARCH4J_EXECUTABLE" -p /System/Library/Frameworks/JavaVM.framework/Home -l ./uninstall/uninst.jar
fi

if [ -e "uninst.flag" ]; then

	rm -rf packages/jre &> /dev/null
	rmdir packages &> /dev/null
	
	rm -rf bin &> /dev/null
	rm -rf tmp &> /dev/null
	rm -rf uninstall &> /dev/null
	rm uninst.flag

	if [ -e "llssite.cfg" ] ; then
		rm llssite.cfg &> /dev/null
	fi

	if [ -e "glisite.cfg" ] ; then
		rm glisite.cfg &> /dev/null
	fi
 	
	CONTENTS=`ls`
	if [ -z "$CONTENTS" ]; then
		GSDEL=`pwd`
		cd ..
		rmdir $GSDEL &> /dev/null
	fi
fi
