@echo off
SETLOCAL
cls
echo.
echo.
echo.

net session >nul 2>nul

if %ERRORLEVEL% GTR 0 (
	echo " Could you please run the script as administrator (Run as Adminisitrator).  "
	goto end
)

cd /d %~dp0

if exist PreCheckSummary.txt del PreCheckSummary.txt /q 

@set serverType=$ServerType

@set paramName=%1
@set paramValue=%2

@set isProxyEnabled=no

IF /I "%paramName%" == "-proxyEnabled" (
	IF /I "%paramValue%" == "yes" (
		@set isProxyEnabled=yes
	)
	IF /I "%paramValue%" == "y" (
		@set isProxyEnabled=yes
	)
)

$RunLogonSimulatorCheck -proxyEnabled %isProxyEnabled%

for /f "delims=" %%x in (PreCheckSummary.txt) do set message=%%x

if "%message%" == "Failure" (
	echo Rerun the setup^.bat as administrator to confirm the same^.
	goto end
) else (
	echo.
	echo.
	echo eG Application is going to be installed...
	echo.
)

@pause

echo ^[InstallShield Silent^] >>eGAgent^.iss
echo Version^=v7^.00 >>eGAgent^.iss
echo File^=Response File >>eGAgent^.iss
echo ^[File Transfer^] >>eGAgent^.iss
echo OverwrittenReadOnly^=NoToAll >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-DlgOrder^] >>eGAgent^.iss
echo Dlg0^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdWelcome^-0 >>eGAgent^.iss
echo Count^=10 >>eGAgent^.iss
echo Dlg1^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdLicense^-0 >>eGAgent^.iss
echo Dlg2^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdAskDestPath^-0 >>eGAgent^.iss
echo Dlg3^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-AskYesNo^-0 >>eGAgent^.iss
echo Dlg4^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdShowDlgEdit2^-0 >>eGAgent^.iss
echo Dlg5^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-AskYesNo^-1 >>eGAgent^.iss
echo Dlg6^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdStartCopy^-0 >>eGAgent^.iss
echo Dlg7^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-AskYesNo^-2 >>eGAgent^.iss
echo Dlg8^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdShowDlgEdit1^-0 >>eGAgent^.iss
echo Dlg9^={EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdFinish^-0 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdWelcome^-0^] >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdLicense^-0^] >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdAskDestPath^-0^] >>eGAgent^.iss
echo szDir^=C:\ >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-AskYesNo^-0^] >>eGAgent^.iss
echo Result^=0 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdShowDlgEdit2^-0^] >>eGAgent^.iss
echo szEdit1^=$MANAGER_IP >>eGAgent^.iss
echo szEdit2^=$MANAGER_PORT >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-AskYesNo^-1^] >>eGAgent^.iss
echo Result^=0 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdStartCopy^-0^] >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo ^[Application^] >>eGAgent^.iss
echo Name^=eG Agent >>eGAgent^.iss
echo Version^=6^.2 >>eGAgent^.iss
echo Company^=eG Innovations, Inc^. >>eGAgent^.iss
echo Lang^=0009 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-AskYesNo^-2^] >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdShowDlgEdit1^-0^] >>eGAgent^.iss
echo szEdit1^=$AGENT_NICK_NAME >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo ^[{EC0B5E31^-F42B^-4B4E^-B764^-45FEA005C954}^-SdFinish^-0^] >>eGAgent^.iss
echo Result^=1 >>eGAgent^.iss
echo bOpt1^=0 >>eGAgent^.iss
echo bOpt2^=0 >>eGAgent^.iss

cls

echo.
echo.

echo eG Application is Installing .... 

echo.
echo.
echo ***********************************************************
echo  This process will take few minutes to complete.
echo  PLEASE DO NOT INTERRUPT THIS PROCESS.
echo ***********************************************************
echo.

if exist eGAgent_win2019_x64.exe (
.\eGAgent_win2019_x64.exe  -s /f1.\eGAgent.iss
)
if exist eGAgent_win2016_x64.exe (
.\eGAgent_win2016_x64.exe  -s /f1.\eGAgent.iss
)
if exist eGAgent_win2012.exe (
.\eGAgent_win2012.exe  -s /f1.\eGAgent.iss
)
if exist eGAgent_win2012_x64.exe (
.\eGAgent_win2012_x64.exe  -s /f1.\eGAgent.iss
)
if exist eGAgent_win2008.exe (
.\eGAgent_win2008.exe  -s /f1.\eGAgent.iss
)
if exist eGAgent_win2008_x64.exe (
.\eGAgent_win2008_x64.exe  -s /f1.\eGAgent.iss
)

if exist C:\eGurkha (
	echo ******************************************************************
	echo The eG Application has been installed successfully!!! 
	echo ******************************************************************
	echo.
	echo.
	@pause
	echo.
	echo.
	if /I "%serverType%" == "Citrix_XcLogon_Emulation" (
		echo *******************************************************************
		echo Install the eGLogoffHelper on the Citrix ZDC ^(in case a Citrix 
		echo XenApp Server v6^.5 is used^), or on the Citrix Delivery 
		echo Controller ^(if Citrix XenDesktop v7^.x is used^)^. This helper 
		echo is required for the application^/desktop logoff to occur^. To 
		echo know how to install the helper, refer to The_eG_Enterprise_Express_
		echo Logon_Simulator_for_Citrix_XenApp_and_XenDesktop document, which 
		echo will be available in the folder into which you extracted the 
		echo eG Agent zip^.
		echo *******************************************************************
	) else (
		echo **********************************************************************
		echo Install the eGLogoffHelper on the VMware Horizon Connection Server^.  
		echo This helper is required for the application^/desktop logoff to occur^. 
		echo To know how to install the helper, refer to The_eG_Enterprise_Express_
		echo Logon_Simulator_for_VMware_Horizon document, which 
		echo will be available in the folder into which you extracted the 
		echo eG Agent zip^.
		echo **********************************************************************
	)
	echo.
	echo.
	if /I "%isProxyEnabled%" == "yes" (
		@pause
		echo.
		echo.
		echo **********************************************************************
		echo Switch to the directory C^:^\eGurkha^\lib and run the  
		echo changeAgentSettings^.bat file to configure the proxy settings^.
		echo **********************************************************************
		echo.
		echo.
	)
	goto end
) else (
	echo ******************************************************************
	echo The eG Application installation failed...
	echo Please contact support@eginnovations.com for further assistance
	echo ******************************************************************
	echo.
	goto end
)
:End

echo.
@pause

ENDLOCAL



