#!/bin/bash
# #################################################################################
# Exceed TurboX Client Launcher
# © Rocket Software, Inc. or its affiliates. All Rights Reserved.
# ROCKET SOFTWARE, INC. CONFIDENTIAL
# #################################################################################
# unregister
# #################################################################################

# unregister script for Exceed TurboX Client Launcher installed with rpm.

if [ "${DEBUGINSTALL}" = "1" ] ; then
	set -x
	export XDG_UTILS_DEBUG_LEVEL=5
	DEBUGSH="set -x"
else
	DEBUGSH=
fi


VERSION=12.0
APP_NAME="Exceed TurboX Client Launcher"
PROD_NAME="${APP_NAME}"

usage()
{
	${ECHO} "Usage: $0 [-s responsefile ]"
}

strlen()
{
	# `expr length "$*"` is not supported in older systems
	strlenresult=`expr "$*" : '.*'`
	return ${strlenresult}
}

printsectmessage()
{
	if [ "${bSilent}" = "1" ] ; then
		return
	fi
	# calculate proper # of = for this header
	strlen $*
	slen=$?
	lpos=0
	suffix=
	while test ${lpos} -lt  ${slen}
	do
		suffix="${suffix}="
		lpos=`expr ${lpos} + 1`
	done
	${ECHO}
	${ECHO} $*
	${ECHO} ${suffix}
	${ECHO}
}

printtitlemessage()
{
	if [ "${bSilent}" = "1" ] ; then
		return
	fi
	# calculate proper # of = for this header
	strlen $*
	slen=$?
	inmarg="    "
	strlen "${inmarg}"
	mlen=$?
	titlewmarg=`echo "${inmarg}$*${inmarg}"`
	strlen "${titlewmarg}"
	tslen=$?
	tslen=`expr ${tslen} - 2`
	lpos=0
	border=
	mborder=
	while test ${lpos} -lt  ${tslen}
	do
		border=`echo ${border}'='`
		mborder=`echo "${mborder} "`
		lpos=`expr ${lpos} + 1`
	done
	${ECHO}
	${ECHO} "${inmarg}*${border}*"
	${ECHO} "${inmarg}*${mborder}*"
	${ECHO} "${inmarg}${titlewmarg}"
	${ECHO} "${inmarg}*${mborder}*"
	${ECHO} "${inmarg}*${border}*"
	${ECHO}
}


cd_and_exit()
{
	resetCDir
	exit $1
}

test_GREP()
{
	${ECHO} ${GREP} -e GREP "$0" > /dev/null 2>&1
	${GREP} -e GREP "$0" > /dev/null 2>&1
	if [ $? -gt 0 ] ; then
		return 1
	else
		return 0
	fi
}

find_good_grep()
{
	GREP=$(which grep 2> /dev/null)
	test_GREP
	if [ $? -gt 0 ] ; then
		GREP=$(which egrep 2> /dev/null)
		test_GREP
		if [ $? -gt 0 ] ; then
			GREP=/usr/xpg4/bin/grep
			test_GREP
			if [ $? -gt 0 ] ; then
				${ECHO} "FATAL ERROR: The grep version on this machine is too old.  It needs to be equivalent to GNU grep."
				cd_and_exit 1
			fi
		fi
	fi
	export GREP
	return
}

logIncident()
{
	if [ "${1}" = "1" ] ; then
		incidentCategory="INFORMATION"
	elif [ "${1}" = "2" ] ; then
		incidentCategory="WARNING"
	elif [ "${1}" = "3" ] ; then
		incidentCategory="FATAL ERROR"
	else
		incidentCategory="UNKNOWN"
	fi

	thisLogFile="${2}"
	smallTab="  "

	${ECHO} "${incidentCategory}: `basename ${0}`" >> "${thisLogFile}"

	if [ ! "${3}x" = "x" ] ; then
		${ECHO} "${smallTab}${3}" >> "${thisLogFile}"
	fi

	if [ ! "${4}x" = "x" ] ; then
		${ECHO} "${smallTab}${4}" >> "${thisLogFile}"
	fi

	if [ ! "${5}x" = "x" ] ; then
		${ECHO} "${smallTab}${5}" >> "${thisLogFile}"
	fi

	if [ ! "${6}x" = "x" ] ; then
		${ECHO} "${smallTab}${6}" >> "${thisLogFile}"
	fi

	if [ ! "${7}x" = "x" ] ; then
		${ECHO} "${smallTab}${7}" >> "${thisLogFile}"
	fi

	if [ ! "${8}x" = "x" ] ; then
		${ECHO} "${smallTab}${8}" >> "${thisLogFile}"
	fi

	if [ ! "${9}x" = "x" ] ; then
		${ECHO} "${smallTab}${9}" >> "${thisLogFile}"
	fi

	${ECHO} >> "${thisLogFile}"
}

resolveDir()
{
	# resolve links - $0 may be a softlink
	thisPRG="${1}"

	while [ -h "$thisPRG" ]; do
		ls_ld=`ls -ld "$thisPRG"`
		this_link=`expr "${ls_ld}" : '.*-> \(.*\)$'`

		if expr "${this_link}" : '/.*' > /dev/null; then
			thisPRG="${this_link}"
		else
			thisPRG=`dirname "${thisPRG}"`/"${this_link}"
		fi
	done

	# -- we only want to check fully resolved path
	if [ "${3}" = "CD" ] ; then
		eval ${2}="${thisPRG}"
		return
	fi

	CDir="${PWD}"

	thisPrgDirName="`dirname ${thisPRG}`"

	cd "${thisPrgDirName}" > /dev/null 2>&1
	cd .. > /dev/null 2>&1

	Here=`pwd`
	#declare "${2}=${Here}"
	eval "$(printf "%q=%q" "${2}" "${Here}")"

	cd "${CDir}"

}

getInstallDir()
{
	resolveDir $0 InstallDir
}

resetCDir()
{
	cd "${CDir}" > /dev/null 2>&1
}

finalize()
{
	resetCDir
	${ECHO} "${PROD_NAME} Uninstallation Complete"
	if [ ! "${DeleteFolder}" = "1" ] ; then
		${ECHO} "${PROD_NAME} Uninstallation Complete" >> "${logfile}"
	fi
}

initialize()
{
	init_variables $*
	export_globals
	display_install_banner
	areYouRoot
	rootUserResult=$?
	init_log_file
}

isItSUSELinux()
{
	if [ -d "/etc/init.d" ] ; then
		isSUSE=1
	fi
}

getThisPlatform()
{
	osAix=aix
	osLinux=linux
	osSolaris=solaris
	osHPUX=hpux

	archPpc=ppc
	archi586=i586
	archx86_64=x86_64
	archSparc=sparc
	archParisc=parisc

	unknown=unknown

	thisOS=${unknown}
	thisArch=${unknown}

	thisUname=`uname`

	fgrepOptions="-c -i"
	optionL="-L"

	hasi86=`uname -a | grep ${fgrepOptions} i386`

	if [ ${hasi86} = "0" ] ; then
		hasi86=`uname -a | grep ${fgrepOptions} i686`
	fi

	isx86_64=`uname -a | grep ${fgrepOptions} x86_64`

	if [ ${hasi86} = "0" ] ; then
		if [ ! ${isx86_64} = "0" ] ; then
			thisArch=${archx86_64}
		fi
	else
		thisArch=${archi586}
	fi

	case ${thisUname} in
		AIX )
			thisOS=${osAix}
			thisArch=${archPpc}
			;;
		Linux )
			thisOS=${osLinux}
			isItSUSELinux
			;;
		SunOS )
			thisOS=${osSolaris}
			if [ ${hasi86}=0 ] ; then
				thisArch=${archSparc}
				optionL="-h"
			fi
			;;
		HP-UX )
			thisOS=${osHPUX}
			thisArch=${archParisc}
			;;
		* )
			;;
	esac
}


addSectionHeader()
{
	if [ "${bSilent}" = "1" ] ; then
		return
	fi

	${ECHO} ""
	${ECHO} "${1}"
	${ECHO} "${2}"
	${ECHO} ""
}

init_variables()
{
	logDir="${InstallDir}/installlogs"
	initFile="${logDir}/init.d"
	logfile="${logDir}/install.log"

	binDir="${InstallDir}/bin"
	binetxlaunchercontrol="${binDir}/etxlauncher"

	conf_dir="${InstallDir}/conf"
	icons_dir="${InstallDir}/icons"

	thisUname=`uname`
	isSparc=`uname -a | ${GREP} -c sparc`

	# TODO - determine if our "latest" instances of xdg are older than local copies
	XDGMIME="${binDir}/xdg-mime"
	XDGICONRESOURCE="${binDir}/xdg-icon-resource"
	export XDGMIME
	export XDGICONRESOURCE

}

export_globals()
{
	export bSilent
	export bBootStart
}

chmodThisDir()
{
	if [ ! "${bSilent}" = "1" ] ; then
		${ECHO} ".\c"
	fi

	chmod $2 "$1" > /dev/null 2>&1

	for f in `ls "$1"` ;
	do
		chmodThisFile "$1/$f" $2 $3
	done
}

chmodThisFile()
{
	if [ -f "$1" ] ; then
		chmod $3 "$1" > /dev/null 2>&1
	elif [ -d "$1" ] ; then
		chmodThisDir "$1" $2 $3
	fi
}

test_ECHO()
{
	${ECHO} -e "test\c" | grep "\-e" > /dev/null
	if [ $? -gt 0 ] ; then
		# -e is supported so add it
		ECHO="${ECHO} -e"
	fi
}

find_good_ECHO()
{
	ECHO=$(which echo 2> /dev/null)
	test_ECHO
	export ECHO
}

set_platform_opts()
{
	find_good_ECHO
	if [ ${OSTYPE:="UNKNOWN"} = "Linux" \
			-o $OSTYPE = "linux-gnu" \
			-o $OSTYPE = "linux" \
			]; then
		USERADDOPTS="-M"
	else
		USERADDOPTS=
	fi

	export USERADDOPTS
}

display_install_banner()
{
	if [ "${bSilent}" = "1" ] ; then
		return
	fi

	InstallBanner="UNINSTALL - ${PROD_NAME}"

	clear
	printtitlemessage "${InstallBanner}"

}

init_log_file()
{
	if [ $ONLYGCONF -gt 0 ] ; then
		return
	fi
	if [ ! -d "${logDir}" ] ; then
		mkdir "${logDir}"
	fi

	logfile="${logDir}/uninstall.log"

	touch "$logfile" 2>/dev/null

	if [ ! "${bSilent}" = "1" ] ; then
		if [ ! -w "$logfile" ] ; then
			${ECHO} "We are unable to create the log $logfile."
			${ECHO} "Would you like to continue anyway?"
			${ECHO} "[y]es or [n]o (<Enter> for no): \c"
			read resp

			if [ "${resp}xxxx" = "yxxxx" -o "${resp}xxxx" = "Yxxxx" ]; then
				logfile=/dev/null
			else
				${ECHO} $ABORTING
				cd_and_exit 1
			fi
		fi
	fi

	${ECHO} > "$logfile"
	${ECHO} "${PROD_NAME} Uninstallation Log" >> "$logfile"
	${ECHO} "#####################################################" >> "$logfile"
	${ECHO} "" >> "$logfile"
	${ECHO} "" >> "$logfile"

	logIncident "1" "${logfile}" "${LOG_DATE}"
}


areYouRoot()
{
	wai=whoami
	noWhoAmI=$(which ${wai} 2> /dev/null | ${GREP} -c "no ${wai}")
	
	if [ "${noWhoAmI}" = "1" -a  -x /usr/ucb/${wai} ] ; then
		wai=/usr/ucb/${wai}
		noWhoAmI=0
	fi

	if [ "${noWhoAmI}" = "0" -a ! "`${wai}`" = "root" ] ; then
		${ECHO}
		${ECHO} "Current user does not have 'root' privileges."
		${ECHO} "Uninstalling ${PROD_NAME} in user mode."
		${ECHO}
		return 1
	else
		${ECHO}
		${ECHO} "Current user has 'root' privileges"
		${ECHO} "Uninstalling ${PROD_NAME} in system mode."
		${ECHO}
		logfile=${logDir}/uninstall-allusers.log
	fi
	return 0
}

display_warning_message()
{
	${ECHO}
	${ECHO} "Warning: ${this_msg}"
}

show_this_warning()
{
	this_log="$1"

	if [ -r ${this_log} ] ; then
		rm -f ${this_log}
	else
		this_msg="$2"
		display_warning_message
	fi
}

setInstallCompleteFlag()
{
	${ECHO} "${InstallCompleteFlag}" >> "${ETXCNProps}"
}

change_owner()
{
	chown $*
}

wrap_it_up()
{
	if [ ! "${DeleteFolder}" = "1" ] ; then
		logIncident "1" "${logfile}" "${PROD_NAME} removed." "${PROD_INSTALL_TIME}"
	fi
}

remove_mime_xml_Gconf()
{
	# if we have gconftool-2 support then unregister ourselves from there as well
	gconftool2=$(which gconftool-2 2> /dev/null)
	if [ $? -eq 0 ] ; then
		if [ "$1" = "system" ] ; then
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etx12/command
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etx12/needs_terminal
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etx12/enabled
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etx12
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etxsr12/command
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etxsr12/needs_terminal
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etxsr12/enabled
			gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults -u /desktop/gnome/url-handlers/etxsr12
			${ECHO} "Warning: global gconf setting changes will not be active for users who are"
			${ECHO} "already logged in.  These users will need to log out and back in."
		fi
		# gconftool requires access for restarting gconfd if none avail then we'll get errors
		# ${DBUS_SESSION_BUS_ADDRESS}
		# turn it off
		gconftool-2 -u /desktop/gnome/url-handlers/etx12/command > /dev/null 2>&1
		gconftool-2 -u /desktop/gnome/url-handlers/etx12/needs_terminal > /dev/null 2>&1
		gconftool-2 -u /desktop/gnome/url-handlers/etx12/enabled > /dev/null 2>&1
		gconftool-2 -u /desktop/gnome/url-handlers/etx12 > /dev/null 2>&1
		gconftool-2 -u /desktop/gnome/url-handlers/etxsr12/command > /dev/null 2>&1
		gconftool-2 -u /desktop/gnome/url-handlers/etxsr12/needs_terminal > /dev/null 2>&1
		gconftool-2 -u /desktop/gnome/url-handlers/etxsr12/enabled > /dev/null 2>&1
		gconftool-2 -u /desktop/gnome/url-handlers/etxsr12 > /dev/null 2>&1

		# remove schema?
	fi
}

handle_removal()
{
	# $1  "system" or "user"  [Not used]
	desktopfileid=etxlauncher12.desktop
	etxdesktopfile="${conf_dir}/${desktopfileid}"
	installed_etxdesktopfile=${share_applications}/${desktopfileid}
	xml_file=x-scheme-handler-etx12.xml
	xmlsr_file=x-scheme-handler-etxsr12.xml

	${ECHO} Remove desktop file
	${ECHO} Remove desktop file >> "${logfile}"
	rm -f "${etxdesktopfile}"
	rm -f ${installed_etxdesktopfile}

	protocolfileid=etx12.protocol
	etxprotocolfile="${conf_dir}/${protocolfileid}"
	etxprotocolfiletemplate="${conf_dir}/${protocolfileid}.template"
	installed_etxprotocolfile=${kde_services_dir}/${etxprotocolfile}
	if [ ! "x${kde_services_dir}" = "x" ] ; then
		rm -f "${etxprotocolfile}"
		rm -f ${installed_etxprotocolfile}
	fi

	protocolsrfileid=etxsr12.protocol
	etxsrprotocolfile="${conf_dir}/${protocolsrfileid}"
	etxsrprotocolfiletemplate="${conf_dir}/${protocolsrfileid}.template"
	installed_etxsrprotocolfile=${kde_services_dir}/${etxsrprotocolfile}
	if [ ! "x${kde_services_dir}" = "x" ] ; then
		rm -f "${etxsrprotocolfile}"
		rm -f ${installed_etxsrprotocolfile}
	fi

	${ECHO} Unregistering x-scheme-handler-etx12 as mime
	${ECHO} Unregistering x-scheme-handler-etx12 as mime >> "${logfile}"
	${ECHO} Unregistering x-scheme-handler-etxsr12 as mime
	${ECHO} Unregistering x-scheme-handler-etxsr12 as mime >> "${logfile}"
	if [ "$1" = "system" ] ; then
		${DEBUGSH} "${XDGMIME}" uninstall --mode system "${conf_dir}/${xml_file}"
		${DEBUGSH} "${XDGMIME}" uninstall --mode system "${conf_dir}/${xmlsr_file}"
	else
		${DEBUGSH} "${XDGMIME}" uninstall "${conf_dir}/${xml_file}"
		${DEBUGSH} "${XDGMIME}" uninstall "${conf_dir}/${xmlsr_file}"
	fi
	rm -f ${share_root_folder}/mime/x-scheme-handler/etx12.xml > /dev/null 2>&1
	rm -f ${share_root_folder}/mime/x-scheme-handler/etxsr12.xml > /dev/null 2>&1

	remove_mime_xml_Gconf $1

	#  remove x-scheme-handler/etx12 from [Default Applications]
	#     section of ~/.local/share/applications/mimeapps.list
	#             or /usr/share/applications/mimeapps.list
	if [ "$1" = "system" ] ; then
		mimeapps=/usr/local/share/applications/defaults.list
		mimeapps2=/usr/share/applications/defaults.list
	else
		mimeapps=~/.local/share/applications/mimeapps.list
		mimeapps2=~/.local/share/applications/mimeapps.list
	fi
	if [ -f ${mimeapps} ] ; then
		awk '!/x-scheme-handler\/etx12=etxlauncher12.desktop/' ${mimeapps} > tmp_mimeapp && mv -f tmp_mimeapp ${mimeapps}
		awk '!/x-scheme-handler\/etxsr12=etxlauncher12.desktop/' ${mimeapps} > tmp_mimeapp && mv -f tmp_mimeapp ${mimeapps}
	else
		if [ -f ${mimeapps2} ] ; then
			awk '!/x-scheme-handler\/etx12=etx12launcher.desktop/' ${mimeapps2} > tmp_mimeapp && mv -f tmp_mimeapp ${mimeapps2}
			awk '!/x-scheme-handler\/etxsr12=etx12launcher.desktop/' ${mimeapps2} > tmp_mimeapp && mv -f tmp_mimeapp ${mimeapps2}
		fi
	fi

	${ECHO} Unregistering Desktop icon
	${ECHO} Unregistering Desktop icon  >> "${logfile}"
	# $1  "system" or "user" [Not used]
	sml_icon=etxlauncher.58.png
	lrg_icon=etxlauncher.128.png

	if [ "$1" = "system" ] ; then
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --mode system --context mimetypes --size  58 "${InstallDir}/icons/${sml_icon}" x-scheme-handler-etx12
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --mode system --context mimetypes --size 128 "${InstallDir}/icons/${lrg_icon}" x-scheme-handler-etx12
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --mode system --context mimetypes --size  58 "${InstallDir}/icons/${sml_icon}" x-scheme-handler-etxsr12
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --mode system --context mimetypes --size 128 "${InstallDir}/icons/${lrg_icon}" x-scheme-handler-etxsr12
	else
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --context mimetypes --size  58 "${InstallDir}/icons/${sml_icon}" x-scheme-handler-etx12
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --context mimetypes --size 128 "${InstallDir}/icons/${lrg_icon}" x-scheme-handler-etx12
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --context mimetypes --size  58 "${InstallDir}/icons/${sml_icon}" x-scheme-handler-etxsr12
		${DEBUGSH} "${XDGICONRESOURCE}" uninstall --context mimetypes --size 128 "${InstallDir}/icons/${lrg_icon}" x-scheme-handler-etxsr12
	fi
}

handle_desktop_xdg_refresh()
{
	# $1  "system" or "user"  [Not used]
	${ECHO} "Updating mime database... this may take some time."
	update-desktop-database ${share_root_folder} > /dev/null 2>&1
	update-mime-database ${share_root_folder} > /dev/null 2>&1
}


main_uninstall()
{
	cd ${InstallDir}/bin

	if [ ! "${bSilent}" = "1" ] ; then
		${ECHO} "This will uninstall ${PROD_NAME}. Would you like to continue?"
		${ECHO} "[y]es or [n]o (<Enter> for no): \c"
		read resp
		${ECHO}

		if [ "${resp}xxxx" = "yxxxx" -o "${resp}xxxx" = "Yxxxx" ]; then
			logIncident "1" "${logfile}" "${PROD_NAME} will be removed." "${PROD_INSTALL_TIME}"
		else
			${ECHO} "Uninstall was cancelled by user."
			cd_and_exit 1
		fi
	fi
	## E.g kde4-config --path services/home/rduser/.kde/share/kde4/services/:/usr/share/kde4/services/
	# Find KDE3 services directory
	kde_user_service_dir=
	kde_global_service_dir=
	kde_global_service_dirs=`kde${KDE_SESSION_VERSION}-config --path services 2> /dev/null`
	# ${ECHO}"kde_global_service_dirs: $kde_global_service_dirs"
	first=
	for x in `echo $kde_global_service_dirs | sed 's/:/ /g'` ; do
		if [ -z "$first" ] ; then
			first=false
			kde_user_service_dir="$x"
		elif [ -w $x ] ; then
			kde_global_service_dir="$x"
		fi
	done
	# ${ECHO} "kde_user_service_dir: $kde_user_service_dir"
	# ${ECHO} "kde_global_service_dir: $kde_global_service_dir"


	if [ ${rootUserResult}  -eq 0 ] ; then
		system_or_user=system
		xdg_system_dirs="$XDG_DATA_DIRS"
		[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share:/usr/share
		for x in `echo $xdg_system_dirs | sed 's/:/ /g'`; do
			# -- do not allow use of /root - ETX-19421
			if [[ $x == "/root/"* ]] ; then
				echo "Skip using folder $x as system XDG folder."
			else
				if [ -w $x ] ; then
					share_root_folder="$x"
					break
				fi
			fi
		done
		if [ -z "$share_root_folder" ] ; then
			${ECHO} "Cannot determine system XDG folder."
			cd_and_exit 1
		fi
		kde_services_dir="${kde_global_service_dir%/}"
	else
		system_or_user=user
		xdg_user_dir="$XDG_DATA_HOME"
		[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
		for x in `echo $xdg_user_dir | sed 's/:/ /g'`; do
			if [ -w $x ] ; then
				share_root_folder="$x"
				break
			fi
		done
		if [ -z "$share_root_folder" ] ; then
			share_root_folder=~/.local/share
			mkdir ~/.local  > /dev/null 2>&1
			mkdir ~/.local/share > /dev/null 2>&1
		fi
		kde_services_dir="${kde_user_service_dir%/}"
	fi
	share_applications=${share_root_folder}/applications
	share_mimexml=${share_root_folder}/mime/packages
	share_pixmaps==${share_root_folder}/pixmaps

	if [ $ONLYGCONF -gt 0 ] ; then
		remove_mime_xml_Gconf $system_or_user
		cd_and_exit 0
	else
		handle_removal $system_or_user
		handle_desktop_xdg_refresh $system_or_user

		if [ ! "${bSilent}" = "1" ] ; then
			${ECHO} "Would you like to remove the ${InstallDir} folder and its contents?"
			${ECHO} "[y]es or [n]o (<Enter> for no): \c"
			read resp
			${ECHO}

			if [ "${resp}xxxx" = "yxxxx" -o "${resp}xxxx" = "Yxxxx" ]; then
				DeleteFolder=1
			else
				DeleteFolder=
			fi
		fi

		# remove files or not
		if [ "${DeleteFolder}" = "1" ] ; then
			${ECHO} Deleting installation directory ${InstallDir}
			# "${logfile}" is now removed so don't bother to write to it anymore
			cd "${InstallDir}"/..
			rm -rf "${InstallDir}"
		fi
	fi
	wrap_it_up
}


readThisSectionKeyValueForThisVariable()
{
	thisPropFile=$1
	thisSection=$2
	thisKey=$3
	thisKeyFullName=${thisSection}.${thisKey}

	tmp_value=`${GREP} "${thisKeyFullName}=" "${thisPropFile}" 2> /dev/null | cut -f2- -d=`
	ret_value=`echo ${tmp_value}|tr -d '\r\n\t'`
	eval ${thisKey}="${ret_value}" > /dev/null 2>&1
}

readThisSectionKeys()
{
	thisPropFile="$1"
	thisSection="$2"
	theseKeys="$3"

	for thisKey in ${theseKeys}
	do
		readThisSectionKeyValueForThisVariable "${thisPropFile}" "${thisSection}" ${thisKey}
	done
}


readResponseFile()
{
	thisResponseFile="$1"

	if [ ! -f "${thisResponseFile}" ] ; then
		${ECHO} "FATAL ERROR: Silent mode response file '${thisResponseFile}' does not exist!"
		cd_and_exit 1
	fi

	theseKeys="DeleteFolder "
	readThisSectionKeys "${thisResponseFile}" "uninstall.etxlauncher" "${theseKeys}"
}


get_params()
{
	builtinResponseFile="${InstallDir}/conf/builtin.resp"

	DeleteFolder="1"
	ONLYGCONF=0

	while [ ! -z "${1}" ]
	do

		case "${1}" in
		-s )
			if [ -z "$2" ] ; then
				usage
			fi
			shift
			bSilent="1"
			readResponseFile "$1"
			;;
		-onlygconf )
			ONLYGCONF=1
			;;
		* )
			${ECHO} "Invalid option: ${1}"
			cd_and_exit 1
			;;
		esac

		shift
	done
}


doIt()
{
	getThisPlatform
	set_platform_opts
	find_good_grep
	getInstallDir
	get_params $*
	initialize
	main_uninstall
	finalize
}

doIt $*

