@echo off
rem AIgo setup bootstrap: always fetch the latest aigo-setup.py from the server, then run it.
rem usage: aigo-setup.cmd            interactive menu
rem        aigo-setup.cmd --silent   install/upgrade without questions
setlocal EnableExtensions
set "BASE=https://pas.zaixiangdu.com"
set "PY=%TEMP%\aigo-setup-latest.py"
set "PYEXE=python"
where py >nul 2>&1 && set "PYEXE=py -3"

echo Fetching AIgo installer...
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { $c=New-Object Net.WebClient; $c.Headers.Add('User-Agent','aigo-setup'); $c.DownloadFile('%BASE%/downloads/updater/aigo-setup.py?t=%RANDOM%','%PY%') } catch { exit 1 }" >nul 2>&1
if not exist "%PY%" (
  echo Download failed: check network/proxy and retry.
  pause
  exit /b 1
)

%PYEXE% "%PY%" %*
set "RC=%ERRORLEVEL%"
del "%PY%" >nul 2>&1
if "%RC%"=="0" exit /b 0
pause
exit /b %RC%
