#!/bin/ksh
echo off
echo `pwd`
ESCUR_DIR=`pwd`

OS=`uname`
PWD=`pwd`
SETUPDIR=${PWD}/InstallableUnits/Installer
OSDIR=""
case ${OS} in
	HP-UX  ) OSDIR=HP ;;
	SunOS ) OSDIR=Solaris ;;
	Linux ) OSDIR=Linux ;;
	AIX   ) OSDIR=AIX ;;
esac

type gunzip >/dev/null 2>&1
result=$?
if [[ $result != 0 ]]; then
	echo "gunzip" is not found in the path. Please be sure that "gunzip" is installed and can be found in the $PATH variable.
	unset ESCUR_DIR
	exit
fi

TAR=tar
if [[ ${OSDIR} == "Solaris" ]]
then
	TAR=gtar
fi

type $TAR >/dev/null 2>&1
result=$?
if [[ $result != 0 ]]; then
	echo "$TAR" is not found in the path. Please be sure that "$TAR" is installed and can be found in the $PATH variable.
	unset ESCUR_DIR
	exit
fi

OLDJAVA_HOME=$JAVA_HOME
OLDPATH=$PATH
if [[ "$TMP" == "" ]]; then
	unset ESEHOME
else
	ESEHOME=$TMP
fi
echo ESEHOME = $ESEHOME
mkdir -p $ESEHOME/tmp/Bundled_JRE
echo copy vm.tar.Z to $ESEHOME/tmp/Bundled_JRE
cp vm.tar.Z $ESEHOME/tmp/Bundled_JRE
cd $ESEHOME/tmp/Bundled_JRE
echo Please wait. Unpacking java vm to $ESEHOME/tmp/Bundled_JRE ...
gunzip vm.tar.Z
$TAR -xf vm.tar
echo move jre files
mv $ESEHOME/tmp/Bundled_JRE/jre/* .
if [[ -d "$ESEHOME/tmp/Bundled_JRE/jre" ]]; then
	rm -r $ESEHOME/tmp/Bundled_JRE/jre;
	rm $ESEHOME/tmp/Bundled_JRE/vm.tar;
fi
JAVA_HOME=$ESEHOME/tmp/Bundled_JRE
echo java home = $JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
echo path = $PATH
cd "$ESCUR_DIR"
echo $ESCUR_DIR
echo $JAVA_HOME/bin/java -Xms40m -Xmx1024m -cp ./../../lib/BaseInstaller.jar:./../../lib/WinRegistry.jar -splash:../../resources/Setup.jpg com.infor.install.MainProgram -j $1 $2 $3
"$JAVA_HOME/bin/java" -Xms40m -Xmx1024m -cp ./../../lib/BaseInstaller.jar:./../../lib/WinRegistry.jar -splash:../../resources/Setup.jpg com.infor.install.MainProgram -j $1 $2 $3
cd "$JAVA_HOME"
chmod -R +w *
wait
cd "$JAVA_HOME/.."
if [[ -d "$JAVA_HOME" ]]; then
	rm -r "$JAVA_HOME"
fi
PATH=$OLDPATH
unset OLDPATH
JAVA_HOME=$OLDJAVA_HOME
unset OLDJAVA_HOME
cd "$ESCUR_DIR"
unset ESCUR_DIR

