ECHO OFF

REM Main script for setting up the web server, including the domain, and preparing the related windows services
REM During the process, various hard coded values in the files will be replaced with the variables defined in this batch file
REM Make sure this script is Run As Administrator, so that the needed Windows service can be installed as well

REM These are the variables that should be set up before you execute this script.

NET SESSION >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
    ECHO.
    ECHO [ERROR] Please run this script as Administrator.
    ECHO Press Enter to exit...
    PAUSE >nul
    EXIT /B
)
ECHO ----------------------------------------------------------------------------------------------
ECHO - Tomcat9 Installation script version 1.0                                                   -
ECHO - The script supports ABSSolute Versions above 9.07.00 for Tomcat9 only                      -
ECHO - The Script supports Tomcat10 update and JAVA JRE update matching the version of ABSSolute  -
ECHO - If JAVA major version is changed add the new version here and modify the JRE update script -
ECHO ----------------------------------------------------------------------------------------------

:SETUPVARIABLES

SET ABS_WEBSERVERHOME=%~dp0
SET ABS_WEBADMINSLOT=81
SET ABS_WEBSERVERSLOT=80
SET ABS_WEBSERVERMEMORY=1024

set /p ABS_WEBSERVERHOME= Please specify the value for ABS_WEBSERVERHOME, the default value is %ABS_WEBSERVERHOME%:
set /p ABS_WEBADMINSLOT= Please specify the value for ABS_WEBADMINSLOT, the default value is %ABS_WEBADMINSLOT%:  
set /p ABS_WEBSERVERSLOT= Please specify the value for ABS_WEBSERVERSLOT, the default value is %ABS_WEBSERVERSLOT%:

SET ABS_WEBSERVERSERVICENAME=ABSS%ABS_WEBSERVERSLOT%_WebSrv

set /p ABS_WEBSERVERSERVICENAME= Please specify the value for ABS_WEBSERVERSERVICENAME, the default value is %ABS_WEBSERVERSERVICENAME%:
set /p ABS_WEBSERVERMEMORY= Please specify the value for ABS_WEBSERVERMEMORY, the default value is %ABS_WEBSERVERMEMORY%:

set ABS_UDP=5%ABS_WEBSERVERSLOT:~2%
set ABS_HTTPS=5%ABS_WEBSERVERSLOT:~2%32

REM === ROOT VERSION SELECT(example: 9.07.00) ===
:ASK_VERSION
echo.
echo Please select the major root ABSOLUTE_VERSION:
echo   1. 9.07.00 - works for 9.07.XX minor versions
echo   2. 9.08.00 - works for 9.8.XX minor versions
::echo   3. 9.10.00 - works for 9.10.XX minor versions
echo.

set /p VERSION_CHOICE=Enter your choice (1,2.3...): 

if "%VERSION_CHOICE%"=="1" set "ABSOLUTE_VERSION=9.07.00" & goto VERSION_OK
if "%VERSION_CHOICE%"=="2" set "ABSOLUTE_VERSION=9.08.00" & goto VERSION_OK
::if "%VERSION_CHOICE%"=="3" set "ABSOLUTE_VERSION=9.10.00" & goto VERSION_OK

echo.
echo ERROR: Invalid choice. Please try again.
goto ASK_VERSION

:VERSION_OK
echo.
echo Selected ABSOLUTE_VERSION=%ABSOLUTE_VERSION%

ECHO  You specified the following values:
ECHO  ABS_HTTPS                   %ABS_HTTPS%
ECHO  ABS_UDP                     %ABS_UDP%
ECHO  Tomcat9 LISTENER            %ABS_LSNR%
ECHO  ABS_WEBSERVERHOME:          %ABS_WEBSERVERHOME%
ECHO  ABS_WEBADMINSLOT:           %ABS_WEBADMINSLOT%
ECHO  ABS_WEBSERVERSLOT:          %ABS_WEBSERVERSLOT%
ECHO  ABS_WEBSERVERSERVICENAME:   %ABS_WEBSERVERSERVICENAME%
ECHO  ABS_WEBSERVERMEMORY:        %ABS_WEBSERVERMEMORY%

(
    echo ABSSOLUTE VERSION IS: %ABSOLUTE_VERSION%
) > "%ABS_WEBSERVERHOME%\ABSSolute_version.ini"

echo.
echo SAVED TO "%ABS_WEBSERVERHOME%\ABSSolute_version.ini"

SET CHOOSE=N
SET /P CHOOSE=Do you want to start the installation? ( Type Y for Yes )
IF /I NOT %CHOOSE%==Y GOTO SETUPVARIABLES

call %ABS_WEBSERVERHOME%custom\install\install.bat %ABS_WEBSERVERHOME% %ABS_WEBADMINSLOT% %ABS_WEBSERVERSLOT% %ABS_WEBSERVERSERVICENAME% %ABS_WEBSERVERMEMORY% %ABS_UDP% %ABS_HTTPS%