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_WEBSERVERSLOT=01
SET ABS_WEBSERVERMEMORY=1024

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

SET ABS_WEBSERVERSERVICENAME=ABSS%ABS_WEBSERVERSLOT%_Tomcat9Srv

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%:

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.08.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_WEBSERVERHOME:          %ABS_WEBSERVERHOME%
ECHO  ABS_WEBSERVERSLOT:          %ABS_WEBSERVERSLOT%
ECHO  ABS_WEBSERVERSERVICENAME:   %ABS_WEBSERVERSERVICENAME%
ECHO  ABS_WEBSERVERMEMORY:        %ABS_WEBSERVERMEMORY%
ECHO  ABSSOLUTE_VERSION:          %ABSSOLUTE_VERSION%

(
    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_WEBSERVERSLOT% %ABS_WEBSERVERSERVICENAME% %ABS_WEBSERVERMEMORY%

endlocal