#!/bin/sh

MSSYS_PLATFORM=SYS_OS_UNIX_LINUX_x86_LIBC6
export MSSYS_PLATFORM

CDROM_DIR=`echo $0 | sed 's/\(.*\)\/.*/\1/'`

case $CDROM_DIR in
  "$0") CDROM_DIR="." ;;
esac

INSTUTIL_DIR=`cd $CDROM_DIR/empinstl/instutil; pwd`


# Check if there is a tty just in case the user run this program 
# through a 'file manager' type interface.
#
X=`tty`

case "$X" in
 "not a tty")
		# this message probably will not be shown at all
		echo "This program needs to run in on tty device" >&2
		exit 1
		;;
esac

if test ! -f $INSTUTIL_DIR/lang.sh
then
	cat <<EOM
File '$INSTUTIL_DIR/lang.sh' not found.
The CDROM is not mounted correctly. Please make sure the file name of
CDROM is displayed in lower case.

Abort ...
EOM
fi

. $INSTUTIL_DIR/msg.sh

INSTALL_DIR=
INSTALL_TEXTMODE=

while :
do
	case "$1" in
	  "")		break
			;;
	  -help)	echo "$MSG_USAGE"
			exit 0
			;;
	  -installdir=*)
			INSTALL_DIR=`echo "$1" | sed -e 's;-installdir=;;'`
			shift
			;;
	  -textmode)
			INSTALL_TEXTMODE=yes
			shift
			;;
	  -tmpdir=*)
			TMPDIR=`echo "$1" | sed -e 's;-tmpdir=;;'`
			shift
			;;
	  *)		echo "$MSG_UNKNOWN_OPTION '$1'"
			exit 1
			;;
	esac
done

test "$TMPDIR" = "" && TMPDIR=/tmp
export TMPDIR

CDROM_DIR=`cd $CDROM_DIR; pwd`
export CDROM_DIR INSTALL_DIR INSTUTIL_DIR INSTALL_TEXTMODE

# Leave the CDROM directory
cd

case "$MSSYS_PLATFORM" in
	SYS_OS_UNIX_IRIX_N32)
		unset LD_LIBRARYN32_PATH
		unset LD_LIBRARY_PATH
		export LD_LIBRARYN32_PATH LD_LIBRARY_PATH
		;;
	SYS_OS_UNIX_SOLARIS*)
		# need to add /usr/local/bin to find tar.
		PATH="$PATH:/usr/local/bin"
		PATH="$PATH:/usr/X/bin"
		export PATH
		;;
esac

case "$MSSYS_PLATFORM" in
	SYS_OS_UNIX_QNX)
		# QNX needs to use bash.  The ksh in QNX 4.25 will not
		# allow a subroutine to use the following syntax
		# cat <<EOM
		#	Should be printed
	        #<<EOM
		# Therefore we use bash instead.
		#
		TMPBASH=$TMPDIR/bash$$
		mkdir $TMPBASH
		cd $TMPBASH
		tar xf $CDROM_DIR/empress/qnx.tar common/gnu/bash > /dev/null 2>&1
		cd
		QNXSHELL=$TMPBASH/common/gnu/bash
		export QNXSHELL

		if test "$INSTALL_TEXTMODE" = "yes"
		then
			$QNXSHELL $INSTUTIL_DIR/inst_t.sh
		else
			$QNXSHELL $INSTUTIL_DIR/inst_g.sh
		fi
		rm -rf $TMPBASH
		;;
	*)
		if test "$INSTALL_TEXTMODE" = "yes"
		then
			exec sh $INSTUTIL_DIR/inst_t.sh
		else
			exec sh $INSTUTIL_DIR/inst_g.sh
		fi
		;;
esac
