#!/bin/sh
# #####################################################################
# Open Text Exceed onDemand Client 8
# Copyright (c) 1997-2011 Open Text Corporation. All Rights Reserved.
# #####################################################################
# oteod_cleanup
# Pre-uninstall cleanup
# $Revision: 7613 $
# #####################################################################

startingDir=`pwd`
cd "`dirname $0`"

. utils/common_utils
. utils/xdg_cleanup
. utils/cde_cleanup

uninstall()
{
	message Start Uninstall ${custom_icon_theme} ${custom_icon_size}

	[ "${support_cde}" = "true" ] && cde_uninstall
	[ "${support_xdg}" = "true" ] && xdg_uninstall ${custom_icon_theme} ${custom_icon_size}

	message Done Uninstall
}

oteod_cleanup()
{
  setup "uninstall"
  
	uninstall ${custom_icon_theme} ${custom_icon_size} > "${uninstall_log}" 2>&1
	fail_msg="Warning: Menu and icon desktop integration may not be completely removed. See '${uninstall_log}' for details."
	
	# avoid leaving extra files in install dir, so rpm can completely remove the directory
	[ -f "${install_log}" ] && rm -f "${install_log}"

  wrapup
}

usage()
{
cat << _USAGE
${thisScriptName}: command line tool for removing integration of Exceed onDemand Client with the desktop including menu, extensions and mime type support.

Synopsis

${thisScriptName} [--theme theme-name] 

${thisScriptName} --oldfiletypes [--theme theme-name] 

${thisScriptName} --oldfileandmimetypes [--theme theme-name] 

To fully cleanup this machine you may have to run this command multiple times using the --theme option, once for each theme that has already had oteod_setup run against it.  Otherwise some files and registration will be left on this machine.
_USAGE
}

exit_success()
{
	if [ $# -gt 0 ]; then
		echo "$@"
		echo
	fi
	exit 0
}

#-----------------------------------------
# Exit script on malformed arguments, not enough arguments
# or missing required option.
# prints usage information

exit_failure_syntax()
{
	if [ $# -gt 0 ]; then
		echo "${thisScriptName}: $@" >&2
		echo "Try '${thisScriptName} --help' for more information." >&2
	else
		usage
	fi
	exit 1
}


thisScriptName=`basename ${0}`

support_oldfiletypes_method=default
support_alias_mode=0

# Loop over all parameters setting any variables as necessary
while [ -n "$1" ]
do
	case $1 in
	  # Support for old filetypes
	  --oldfiletypes)
		support_oldfiletypes_method=oldfiletypes
		if [ "${support_oldfiletypes_method}" = "oldfileandmimetypes" ] ; then
			# error
			exit_failure_syntax "--oldfiletypes cannot be used at the same time as --oldfileandmimetypes"
		fi
		echo "Uninstalling with old file type compatability mode on"
	  ;;
	  # Support for old file and mimetypes
	  --oldfileandmimetypes)
		support_oldfiletypes_method=oldfileandmimetypes
		if [ "${support_oldfiletypes_method}" = "oldfiletypes" ] ; then
			# error
			exit_failure_syntax "--oldfileandmimetypes cannot be used at the same time as --oldfiletypes"
		fi
		echo "Uninstalling with old file and mime type compatability mode on"
	  ;;
	  # Support for theme
	  --theme)
		shift
		if [ ! -n "$1" ] ; then
			echo "Warning: --theme is missing theme-name parameter (defaulting to hicolor)"
		else
			custom_icon_theme="--theme $1"
			echo "Uninstalling using ${custom_icon_theme}"
		fi
	  ;;
	  # Support for size 
	  # Note: Testing purposes only since it needs different sized icons to work properly. Only 48x48 is provided.
	  --size)
		shift
		if [ ! -n "$1" ] ; then
			echo "Warning: --size is missing iconSize parameter (defaulting to 48x48)"
		else
			custom_icon_size="--iconSize $2"
			echo "Uninstalling using ${custom_icon_size}"
		fi
	  ;;
	  # Support for usage
	  --help)
		usage
		exit_success
	  ;;
	  # Check for other secondary options
	  *)
		exit_failure_syntax "unknown command '$1'"
	  ;;
	esac
	shift
done


oteod_cleanup $*
