@echo off
echo off
setlocal EnableDelayedExpansion
rem -----------------------------------------------
rem this shell for an unified installation(window)
rem -----------------------------------------------

set script_path=%cd%
cd %script_path%
cd .. > nul
set install_path=%cd%
set HA_PROXY_IP=%1
set PROXY_PORT="8089"
%install_path%\AgentAssistPython\python.exe %install_path%\AgentAssist\bin\assist\agentassisthandle\update_ak_sk.py "%install_path%"
if %errorlevel% == 1 (
	exit /b 1
)

if "%HA_PROXY_IP%" == "" (
    exit /b 0
)

call %install_path%\AgentAssist\download_cert.bat %install_path% %HA_PROXY_IP%
if %errorlevel% == 1 (
	exit /b 1
)

set INSTALL_PYTHON_PATH=%install_path%\AgentAssistPython
%INSTALL_PYTHON_PATH%\python.exe %install_path%\AgentAssist\bin\assist\connectivity.py %install_path% "%HA_PROXY_IP%" "%PROXY_PORT%"
if %errorlevel% == 1 (
    echo Connect to the server failed, please check whether the entered IP address is correct.
    exit /b 1
)

call %install_path%\AgentAssist\bin\assist\agentassisthandle\restart.bat "%install_path%\AgentAssist"

exit /b 0
