diff --git a/OGP64/agent_update.bat b/OGP64/agent_update.bat new file mode 100644 index 0000000..243d5a5 --- /dev/null +++ b/OGP64/agent_update.bat @@ -0,0 +1,131 @@ +@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 diff --git a/docs/WINDOWS_AGENT_UPDATE_BAT.md b/docs/WINDOWS_AGENT_UPDATE_BAT.md new file mode 100644 index 0000000..2f01a61 --- /dev/null +++ b/docs/WINDOWS_AGENT_UPDATE_BAT.md @@ -0,0 +1,118 @@ +# Windows Agent Update BAT + +Workspace reference: [`GSP-WORKSPACE.md`](../../GSP-WORKSPACE.md) + +## Purpose + +`Update-Agent.bat` updates the Git-managed GSP Windows Agent repository, stops the agent first, and starts it again after the update. + +It is intentionally small and local: + +- no Task Scheduler changes +- no installer execution +- no customer data cleanup +- no deletion of game server folders, configs, logs, or Workshop data + +## File location + +Place `Update-Agent.bat` in the repository root: + +- example checkout: `C:\GSP\windows-agent\Update-Agent.bat` + +The current repository layout expects the managed start and stop launchers here: + +- `OGP64\agent_start.bat` +- `OGP64\agent_stop.bat` + +If those are missing, the updater tries the obvious fallback launchers: + +- `OGP64\OGP\Install\agent_start.bat` +- `OGP64\OGP\Install\agent_stop.bat` + +## How to run it + +1. Right-click `Update-Agent.bat`. +2. Choose `Run as Administrator`. +3. Review the console output. +4. Press a key at the end so the window closes only after you read the result. + +## How it works + +The script: + +1. verifies Administrator privileges +2. verifies the agent repository path +3. verifies `.git` exists +4. verifies `git` is available +5. stops the agent with the existing stop BAT if available +6. runs `git fetch origin` +7. runs `git reset --hard origin/unstable` +8. starts the agent with the existing start BAT if available +9. pauses so the operator can read any errors + +## Editable variables + +At the top of `Update-Agent.bat`: + +- `AGENT_DIR` +- `BRANCH` +- `START_BAT` +- `STOP_BAT` + +Default branch: + +- `unstable` + +## Changing branch + +Edit: + +```bat +set "BRANCH=unstable" +``` + +to another remote branch name if needed. + +The script resets to: + +```bat +origin/%BRANCH% +``` + +## Relationship to start and stop BAT files + +`Update-Agent.bat` does not replace the existing launchers. + +It reuses: + +- `OGP64\agent_stop.bat` +- `OGP64\agent_start.bat` + +That keeps update behavior aligned with the normal manual agent lifecycle. + +## Task Scheduler note + +This task does not modify Task Scheduler. + +The agent can still be configured separately to start at boot through Task Scheduler. `Update-Agent.bat` is a manual administrative update helper, not a scheduled task installer. + +## What should stay outside the Git-managed directory + +Do not place customer-owned runtime data inside the Git checkout if you want updates to remain low-risk. + +Keep these outside the Git-managed repository when possible: + +- hosted game server folders +- save files +- customer uploads +- customer scripts +- customer configs +- logs you want preserved independently of code updates + +The repository should contain the Windows agent code and bundled runtime files, not mutable customer data. + +## Assumptions + +- The Git checkout root is the correct update boundary. +- The active branch should be `unstable` by default. +- The existing root launchers under `OGP64\` are the preferred lifecycle scripts.