@echo off
setlocal enabledelayedexpansion
REM redeploy.bat - trigger a remote deploy FROM YOUR LAPTOP (Windows).
REM Double-click, or run from a terminal. Pass deploy.sh flags through:
REM   redeploy.bat               pull latest + rebuild
REM   redeploy.bat --no-pull     rebuild current checkout
REM   redeploy.bat --rollback    restore newest backup on the server
REM
REM Password order: %DEPLOY_PASS%  ->  deploy.secret file  ->  prompt.

set "HOST=118.95.33.89"
set "PORT=61"
set "USER=root"
set "APPDIR=/opt/bizgaze-support"

REM Locate plink
set "PLINK=plink"
where plink >nul 2>nul || set "PLINK=C:\Program Files\PuTTY\plink.exe"

REM Resolve password
set "PW=%DEPLOY_PASS%"
if "!PW!"=="" if exist "%~dp0deploy.secret" set /p PW=<"%~dp0deploy.secret"
if "!PW!"=="" set /p "PW=Server password for %USER%@%HOST%: "

echo ==^> Triggering deploy on %USER%@%HOST% (%APPDIR%) ...
"%PLINK%" -ssh -batch -P %PORT% -pw "!PW!" %USER%@%HOST% "cd %APPDIR% && bash deploy.sh %*"
endlocal
