ECHO OFF

REM Batch file for deploying web components to a running TomEE instance

SET PATH=%PATH%;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
SET ABS_WEBSERVERHOME=%1
SET ABS_WEBSERVERPORT=%2
SET WEBCOMPONENT=%3
SET UDPPORT=%4
SET PWD=tcadmin01
SET ABS_DEPLOYHOME=%ABS_WEBSERVERHOME%deploy\%WEBCOMPONENT%
SET ABS_WEBAPPS=%ABS_WEBSERVERHOME%webapps
SET WARFILE=%ABS_DEPLOYHOME%\%WEBCOMPONENT%.war

ECHO Deploy WAR file webcomponent with the following parameters:

ECHO Web server home:           %ABS_WEBSERVERHOME%
ECHO Web server port:           %ABS_WEBSERVERPORT%
ECHO Web component name:        %WEBCOMPONENT%
REM ECHO Web war name:          %WEBCOMPONENT%.war

REM ECHO Rebuilding the war file 
copy /Y %ABS_WEBSERVERHOME%custom\deploy\AbsSnmpAgentSettings.properties %ABS_WEBSERVERHOME%deploy\%WEBCOMPONENT%\WEB-INF\AbsSnmpAgentSettings.properties > nul
call %ABS_WEBSERVERHOME%custom\bin\replace_values_in_file.bat %ABS_WEBSERVERHOME% [UDPPORT] %UDPPORT% %ABS_WEBSERVERHOME%deploy\%WEBCOMPONENT%\WEB-INF\AbsSnmpAgentSettings.properties > nul
call %ABS_WEBSERVERHOME%\custom\deploy\prepare_war_file.bat %ABS_WEBSERVERHOME% %WEBCOMPONENT% > nul

REM Deploy SNMPagend tolder and webcomponent
ECHO Deploying %WEBCOMPONENT%

REM robocopy %ABS_DEPLOYHOME% %ABS_WEBAPPS%\%WEBCOMPONENT% /COPYALL /E /IS /IT /NFL /NDL /NJH /NJS /nc /ns /np
REM xcopy /s %ABS_DEPLOYHOME% %ABS_WEBAPPS%\%WEBCOMPONENT%\ > nul

%ABS_WEBSERVERHOME%custom\curl\bin\curl -k -u admin:%PWD% --upload-file %WARFILE% https://localhost:%ABS_WEBSERVERPORT%/manager/text/deploy?path=/%WEBCOMPONENT%
%ABS_WEBSERVERHOME%custom\curl\bin\curl -k -u admin:%PWD% https://localhost:%ABS_WEBSERVERPORT%/manager/text/start?path=/%WEBCOMPONENT%

REM ---------------------------------------
ECHO SNMP Check
>nul chcp 65001 
setlocal enabledelayedexpansion
set "_spc=     "
set "_bar=■■■■■" 
set "_msg= Check %WEBCOMPONENT% deployment"
for /f %%a in ('copy/Z "%~dpf0" nul')do for /f skip^=4 %%b in ('echo;prompt;$H^|cmd')do set "BS=%%b" & set "CR=%%a"
for /l %%L in (1 1 5)do <con: set/p "'=!CR!!BS!!CR![!_bar:~0,%%~L!!BS!!_spc:~%%L!]!_msg!"<nul & >nul timeout.exe 1
ECHO .
REM -----------------------------------------
REM curl deploy parameters:
REM curl -k -u admin:%PWD% --upload-file %WARFILE% https://localhost:%ABS_WEBSERVERPORT%/manager/text/deploy?path=/%WEBCOMPONENT%
REM curl -k -u admin:%PWD% https://localhost:%ABS_WEBSERVERPORT%/manager/text/stop?path=/%WEBCOMPONENT%
REM curl -k -u admin:%PWD% https://localhost:%ABS_WEBSERVERPORT%/manager/text/start?path=/%WEBCOMPONENT%
REM -----------------------------------------
REM ECHO Finished...