#
#	getuname
#

getuname ()
{
	file=/tmp/getuname$$
	echo "" > $file

	set -- `ls -l $file`
	NAME="$3"
	rm -fr $file
	echo $NAME
	rm -fr $file
}

#
#	sysname
#

sysuname ()
{
	if (hostname) > /dev/null 2>&1
	then
		hostname
	else
		uname -n
	fi
}

#
#	where_is
#

where_is ()
{
	prog=$1
	PTH=`echo $PATH | sed -e "s/:/ /"g`
	PTH="$PTH /bin /usr/bin /usr/local/bin"

	for I in $PTH
	do
		if test -x $I/$prog && test -f $I/$prog
		then
			echo "$I/$prog"
			return
		fi
	done
	echo
}

#
#	ynq
#

yes=0
no=1
quit=2
tryagain=3

ynq ()
{
	default=
	default_ans=$1
	help_avail=$2

	case $1 in
	 y)	default="[y]" ;;
	 n)	default="[n]" ;;
	esac

	case $help_avail in
	 "")	choice="(y/n/q)" ;;
	 *)	choice="(y/n/q/h/?)" ;;
	esac

	choice="$choice $default"

	echon "$choice "

	read ans

	test "$ans" = "" && ans=$default_ans

	case "$ans" in
	 y | Y | yes | Yes) return $yes ;;
	 n | N | no | NO) return $no ;;
	 q | Q | quit | QUIT) return $quit ;;
	 "?" | h* | H*) 
		case $help_avail in
		  "")	echo "Please enter y, n or q" >&2
			return $tryagain ;;
		  *)	showmsg
			return $tryagain ;;
		esac
		;;
	 *)	
		case $help_avail in
		   "")
			echo "Please enter y, n or q" >&2
			;;
		   *)
			echo "Please enter y, n, q, h or ?" >&2
			;;
		esac
		return $tryagain ;;
	esac
}

#
#	clear_screen
#

CLEAR_SCREEN_UNAME_A=`uname -a`

clear_screen ()
{
	# disable it
	return

	case "$CLEAR_SCREEN_UNAME_A" in
	  QNX*)
		/usr/bin/clear
		;;
	  *)	clear
		;;
	esac
}

#
#	get shell information
#

get_shell_info ()
{
	#
	# set:
	#	LOGIN_SHELL
	#	LOGIN_CLASS
	#	SHELL_STARTUP_FILE
	#
	LOGIN_SHELL=`$EMPRESSPATH/instbin/chkuser -shell`

	if test "$LOGIN_SHELL" = ""
	then
		#
		# if the shell entry of /etc/passwd is empty, we assume
		# it uses /bin/sh as the default shell.
		# For example, the chsh command in Linux (RedHat 4.2)
		# empty the shell field of the passwd if the user changes
		# his shell to /bin/sh.
		#
		LOGIN_SHELL=/bin/sh
	fi

	case $LOGIN_SHELL in
	  */bash)
		SHELL_CLASS=sh
		SHELL_STARTUP_FILE=$HOME/.profile
		test -f $HOME/.bash_profile && \
			SHELL_STARTUP_FILE=$HOME/.bash_profile
		;;
	  */csh)
		SHELL_CLASS=csh
		SHELL_STARTUP_FILE=$HOME/.cshrc

		#
		# if /bin/csh is a symbolic link to /bin/tcsh
		#
		if test -f /bin/tcsh && cmp -s $LOGIN_SHELL /bin/tcsh && \
			test -f $HOME/.tcshrc
		then
			SHELL_STARTUP_FILE=$HOME/.tcshrc
		fi
		;;
	  */sh)
		SHELL_CLASS=sh
		SHELL_STARTUP_FILE=$HOME/.profile

		#
		# If /bin/sh is a symbolic link to /bin/bash.
		#
		if test -f /bin/bash && \
			cmp -s $LOGIN_SHELL /bin/bash && \
			test -f $HOME/.bash_profile
		then
			SHELL_STARTUP_FILE=$HOME/.bash_profile
		fi
		;;
	  */ksh)
		SHELL_CLASS=sh
		SHELL_STARTUP_FILE=$HOME/.profile
		;;
	  */tcsh)
		SHELL_CLASS=csh
		SHELL_STARTUP_FILE=$HOME/.cshrc
		test -f $HOME/.tcshrc && SHELL_STARTUP_FILE=$HOME/.tcshrc
		;;
	  *)
		LOGIN_SHELL=unknown
		SHELL_CLASS=unknown
		SHELL_STARTUP_FILE=
		;;
	esac
}

#
#	pager
#

PAGER=`where_is more`
test "$PAGER" = "" && PAGER=`where_is less`
test "$PAGER" = "" && PAGER=`where_is pg`
test "$PAGER" = "" && PAGER=cat

pager ()
{
	$PAGER $*
}

#
#	clean up
#

installation_cleanup ()
{
	# just in case EMPRESSPATH is set to something real by mistake
	case $EMPRESSPATH in
	    $TMPDIR/*)	;;
	    *)	return	;;
	esac

	echo_message "$MSG_INFO_CLEANUP"
	cd
	rm -fr $EMPRESSPATH
	echo_message "$MSG_INFO_DONE"
}

##############################################################
#	do_you_want_to_continue
##############################################################

do_you_want_to_continue ()
{
	X=y
	test "$1" = "" || X=$1

	while :
	do
		echon "Do you want to continue? "

		ynq $X

		case $? in
		 $yes)		return ;;
		 $quit | $no)	installation_cleanup
				exit 1
				;;
		 *)		continue ;;
		esac
	done
}

##############################################################
#	hit enter to continue
##############################################################

hit_enter_to_continue ()
{
	echon "<Please press Enter key to continue> "
	read X
	case $X in
	   q* | Q*)
			echo "Abort ..."
			installation_cleanup
			exit 1
			;;
	esac
}


##############################################################
#	message for non-native machine
##############################################################

non_native_machine ()
{
	clear_screen
	PLATFORM=`cat $INSTUTIL_DIR/system`

	echo_message "$MSG_WRONG_PLATFORM" "$PLATFORM"
	echo_message "$MSG_WIN32_DRIVER"
}
