Files
GEWU_agent/update_gewu.bat
T

69 lines
1.8 KiB
Batchfile

@echo off
setlocal
set "PACK=%~dp0"
if "%~1"=="" (
for %%I in ("%PACK%..") do set "WORKSPACE=%%~fI"
) else (
for %%I in ("%~1") do set "WORKSPACE=%%~fI"
)
set "DEST=%WORKSPACE%\.agents\gewu"
echo [1/3] Pulling GEWU agent updates...
git -C "%PACK%" pull --ff-only
if errorlevel 1 goto :pull_failed
echo [2/3] Verifying the pulled pack...
python "%PACK%scripts\manifest_tool.py" verify
if errorlevel 1 goto :source_verify_failed
if not exist "%DEST%\" (
echo Installed GEWU pack not found: "%DEST%"
echo For a new project, use scripts\install.py install first.
exit /b 1
)
for /f %%I in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd-HHmmss"') do set "STAMP=%%I"
if not defined STAMP (
echo Could not create a backup timestamp.
exit /b 1
)
set "BACKUP=%WORKSPACE%\.agents\gewu-backup-%STAMP%"
echo Backing up the installed pack to "%BACKUP%"...
robocopy "%DEST%" "%BACKUP%" /E /COPY:DAT /R:2 /W:1
if errorlevel 8 goto :backup_failed
echo [3/3] Updating the installed pack...
robocopy "%PACK%" "%DEST%" /MIR /XD .git __pycache__ /XF .git /R:2 /W:1
if errorlevel 8 goto :copy_failed
python "%DEST%\scripts\manifest_tool.py" verify
if errorlevel 1 goto :installed_verify_failed
echo GEWU agent pack successfully updated and verified!
echo Backup: "%BACKUP%"
exit /b 0
:pull_failed
echo Git pull failed.
exit /b 1
:source_verify_failed
echo The pulled GEWU pack failed manifest verification.
exit /b 1
:backup_failed
echo Backup failed; the installed pack was not updated.
exit /b 1
:copy_failed
echo Pack copy failed. The previous pack backup is at "%BACKUP%".
exit /b 1
:installed_verify_failed
echo Installed pack verification failed. Restoring the backup...
robocopy "%BACKUP%" "%DEST%" /MIR /R:2 /W:1
echo Check the backup at "%BACKUP%" if restore or verification still fails.
exit /b 1