131 lines
3.4 KiB
Batchfile
131 lines
3.4 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions
|
|
|
|
REM GSP Windows Agent Git updater
|
|
REM Run this file as Administrator from the Git-managed agent repository.
|
|
|
|
REM Editable settings
|
|
set "AGENT_DIR=%~dp0"
|
|
if "%AGENT_DIR:~-1%"=="\" set "AGENT_DIR=%AGENT_DIR:~0,-1%"
|
|
set "BRANCH=unstable"
|
|
set "START_BAT=%AGENT_DIR%\OGP64\agent_start.bat"
|
|
set "STOP_BAT=%AGENT_DIR%\OGP64\agent_stop.bat"
|
|
set "FALLBACK_START_BAT=%AGENT_DIR%\OGP64\OGP\Install\agent_start.bat"
|
|
set "FALLBACK_STOP_BAT=%AGENT_DIR%\OGP64\OGP\Install\agent_stop.bat"
|
|
|
|
echo ========================================
|
|
echo GSP Windows Agent Update
|
|
echo ========================================
|
|
echo Agent repository: %AGENT_DIR%
|
|
echo Branch: %BRANCH%
|
|
echo.
|
|
|
|
REM Confirm Administrator privileges
|
|
net session >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo ERROR: Administrator privileges are required.
|
|
echo Right-click Update-Agent.bat and choose "Run as Administrator".
|
|
goto :fail
|
|
)
|
|
|
|
if not exist "%AGENT_DIR%" (
|
|
echo ERROR: Agent directory does not exist:
|
|
echo %AGENT_DIR%
|
|
goto :fail
|
|
)
|
|
|
|
if not exist "%AGENT_DIR%\.git" (
|
|
echo ERROR: .git was not found in:
|
|
echo %AGENT_DIR%
|
|
echo This updater only works inside the Git-managed Windows Agent repository.
|
|
goto :fail
|
|
)
|
|
|
|
where git >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo ERROR: git was not found in PATH.
|
|
echo Install Git for Windows or add git.exe to PATH before running this updater.
|
|
goto :fail
|
|
)
|
|
|
|
if not exist "%STOP_BAT%" (
|
|
echo WARNING: Stop BAT not found:
|
|
echo %STOP_BAT%
|
|
if exist "%FALLBACK_STOP_BAT%" (
|
|
echo Using fallback stop BAT:
|
|
echo %FALLBACK_STOP_BAT%
|
|
set "STOP_BAT=%FALLBACK_STOP_BAT%"
|
|
) else (
|
|
echo WARNING: No stop BAT fallback was found. The update will continue without stopping the agent first.
|
|
set "STOP_BAT="
|
|
)
|
|
)
|
|
|
|
if not exist "%START_BAT%" (
|
|
echo WARNING: Start BAT not found:
|
|
echo %START_BAT%
|
|
if exist "%FALLBACK_START_BAT%" (
|
|
echo Using fallback start BAT:
|
|
echo %FALLBACK_START_BAT%
|
|
set "START_BAT=%FALLBACK_START_BAT%"
|
|
) else (
|
|
echo WARNING: No start BAT fallback was found. The update will not be able to restart the agent automatically.
|
|
set "START_BAT="
|
|
)
|
|
)
|
|
|
|
if defined STOP_BAT (
|
|
echo Stopping agent using:
|
|
echo %STOP_BAT%
|
|
call "%STOP_BAT%"
|
|
if errorlevel 1 (
|
|
echo WARNING: Stop BAT returned errorlevel %ERRORLEVEL%.
|
|
echo Continuing because the Git update itself is still safe to attempt.
|
|
)
|
|
echo.
|
|
)
|
|
|
|
pushd "%AGENT_DIR%" >nul
|
|
|
|
echo Fetching latest Git data from origin...
|
|
git fetch origin
|
|
if errorlevel 1 (
|
|
popd >nul
|
|
echo ERROR: git fetch origin failed.
|
|
goto :fail
|
|
)
|
|
|
|
echo Resetting working tree to origin/%BRANCH%...
|
|
git reset --hard "origin/%BRANCH%"
|
|
if errorlevel 1 (
|
|
popd >nul
|
|
echo ERROR: git reset --hard origin/%BRANCH% failed.
|
|
goto :fail
|
|
)
|
|
|
|
popd >nul
|
|
echo.
|
|
|
|
if defined START_BAT (
|
|
echo Restarting agent using:
|
|
echo %START_BAT%
|
|
call "%START_BAT%"
|
|
if errorlevel 1 (
|
|
echo ERROR: Start BAT returned errorlevel %ERRORLEVEL%.
|
|
goto :fail
|
|
)
|
|
) else (
|
|
echo WARNING: No start BAT was available. Update finished, but the agent was not restarted automatically.
|
|
)
|
|
|
|
echo.
|
|
echo SUCCESS: GSP Windows Agent update completed.
|
|
echo The updater only changed the Git-managed repository and did not intentionally delete configs, logs, server files, or customer data.
|
|
pause
|
|
exit /b 0
|
|
|
|
:fail
|
|
echo.
|
|
echo Update-Agent.bat failed.
|
|
pause
|
|
exit /b 1
|