@echo off
setlocal

set "SERVER=https://2f.aiwearlab.com"
set "AGENT_EXE=%~dp0agent\remote-devops-agent-win7.exe"
if not exist "%AGENT_EXE%" set "AGENT_EXE=%~dp0remote-devops-agent-win7.exe"
set "AGENT_PYTHON=%~dp0agent\python.exe"

if exist "%AGENT_EXE%" (
  set "AGENT_MODE=exe"
) else if exist "%AGENT_PYTHON%" (
  set "AGENT_MODE=python"
) else (
  echo Agent executable was not found in agent\ or next to this script.
  echo Expected either agent\remote-devops-agent-win7.exe or agent\python.exe.
  pause
  exit /b 1
)

echo RemoteDevops one-time agent run
echo Server: %SERVER%
echo.
echo If this machine is not paired yet, a 4-digit code will appear.
echo Send that code to the administrator and keep this window open.
echo.

if "%AGENT_MODE%"=="python" (
  "%AGENT_PYTHON%" -m remote_admin.agent.windows_agent --server "%SERVER%" --name "%COMPUTERNAME%"
) else (
  "%AGENT_EXE%" --server "%SERVER%" --name "%COMPUTERNAME%"
)
echo.
echo Agent stopped with exit code %ERRORLEVEL%.
pause
