#!/bin/sh
# #####################################################################
# Open Text Exceed onDemand Client 8
# Copyright (c) 1997-2011 Open Text Corporation. All Rights Reserved.
# #####################################################################
# oteod_setup
# Post install setup 
# $Revision: 7613 $
# #####################################################################

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

. utils/common_utils
. utils/xdg_setup
. utils/cde_setup

install()
{
	message Start Install  ${custom_icon_theme} ${custom_icon_size}
	eodxc="${oteodHome}/eodxc"

	if [ ! -x "${eodxc}" ]; then
		echo "ERROR: ${eodxc} is not found or not executable." >&2
		DI_GLOBAL_ERROR=true
	fi


	[ "${support_cde}" = "true" ] && cde_install
	[ "${support_xdg}" = "true" ] && xdg_install ${custom_icon_theme} ${custom_icon_size}


	message Done Install
}

oteod_setup()
{ 
	setup "install"
	install  ${custom_icon_theme} ${custom_icon_size}  > "${install_log}" 2>&1
	fail_msg="Warning: Menu and icon desktop integration may not be complete. See '${install_log}' for details."  

  wrapup
}

usage()
{
cat << _USAGE
${thisScriptName}: command line tool for integrating 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 see icons for file extenions in themes other than hicolor you may have to run this command multiple times using the --theme option, once for each supported theme being used on this machine. 

See also the oteod_cleanup for information on how to remove the integration features added by this command.
_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 "Installing 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 "Installing 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 "Installing 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 "Installing using ${custom_icon_size}"
		fi
	  ;;
	  # Support for test_alias 
	  # Note: Testing purposes only
	  --test_alias)
		if [ ! "${support_oldfiletypes_method}" = "oldfiletypes" ] ; then
			# warning
			echo "Warning: --test_alias can only be used with --oldfiletypes.  This option is ignored."
		else
			support_alias_mode=1
			echo "Installing with alias support [testing purposes only]"
		fi
	  ;;
	  # Support for test_alias 
	  # Note: Testing purposes only
	  --test_higherpriority)
		if [ ! "${support_oldfiletypes_method}" = "oldfiletypes" ] ; then
			# warning
			echo "Warning: --test_higherpriority can only be used with --oldfiletypes.  This option is ignored."
		else
			support_increase_priority=1
			echo "Installing with higher priority support [testing purposes only]"
		fi
	  ;;

	  # Support for usage
	  --help)
		usage
		exit_success
	  ;;
	  # Check for other secondary options
	  *)
		exit_failure_syntax "unknown command '$1'"
	  ;;
	esac
	shift
done


oteod_setup $*
