igneum/proto-cuda/windows-app/upload-log.bat

47 lines
2.4 KiB
Batchfile

@echo off
rem Igneum miner log uploader. Sends the last 256 KB of a log file to the Igneum log intake
rem so Claude on the Mac can read it (node tools/logs.mjs). Needs Windows 10 or 11 (curl.exe, PowerShell).
rem Usage: upload-log.bat <logfile> <label> [run_id]
rem run_id falls back to the IGNEUM_RUN_ID environment variable, then to <label>-<date>-<time>.
rem The key only authorises log uploads. It is not in the repository (rotation phase 2, 5 October 2026): it comes from
rem the IGNEUM_LOG_KEY environment variable, else from igneum-log-key.txt next to this script (one line; the packager
rem writes it from the file IGNEUM_INTAKE_KEY_FILE names), else the upload is refused with exit 3.
setlocal
set "IGNEUM_LOG_URL=https://igneum-six.vercel.app/api/log"
if "%IGNEUM_LOG_KEY%"=="" if exist "%~dp0igneum-log-key.txt" set /p IGNEUM_LOG_KEY=<"%~dp0igneum-log-key.txt"
if "%IGNEUM_LOG_KEY%"=="" (
echo upload-log: no intake key: set IGNEUM_LOG_KEY or put igneum-log-key.txt next to this script
exit /b 3
)
if "%~1"=="" goto usage
if "%~2"=="" goto usage
if not exist "%~1" (
echo upload-log: file not found: %~1
exit /b 2
)
set "LOGFILE=%~f1"
set "LABEL=%~2"
set "RUNID=%~3"
if "%RUNID%"=="" set "RUNID=%IGNEUM_RUN_ID%"
set "OUT=%TEMP%\igneum-upload-%RANDOM%.json"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $fs=New-Object IO.FileStream($env:LOGFILE,[IO.FileMode]::Open,[IO.FileAccess]::Read,[IO.FileShare]::ReadWrite); $b=New-Object byte[] $fs.Length; [void]$fs.Read($b,0,$b.Length); $fs.Close(); $n=[Math]::Min($b.Length,262144); $t=[Text.Encoding]::UTF8.GetString($b,$b.Length-$n,$n); $r=$env:RUNID; if (-not $r) { $r=$env:LABEL + '-' + (Get-Date -Format 'yyyyMMdd-HHmm') }; $o=@{label=$env:LABEL;machine=$env:COMPUTERNAME;run_id=$r;lines=$t}; [IO.File]::WriteAllText($env:OUT,(ConvertTo-Json $o -Compress),(New-Object Text.UTF8Encoding $false)); Write-Host ('upload-log: run_id ' + $r + ', ' + $n + ' bytes')"
if errorlevel 1 (
echo upload-log: could not read or encode %LOGFILE%
exit /b 3
)
curl.exe -sS --max-time 60 -X POST "%IGNEUM_LOG_URL%" -H "Content-Type: application/json" -H "x-igneum-key: %IGNEUM_LOG_KEY%" --data-binary "@%OUT%"
set "RC=%ERRORLEVEL%"
echo.
del "%OUT%" >nul 2>&1
if not "%RC%"=="0" (
echo upload-log: curl failed with code %RC%
exit /b %RC%
)
exit /b 0
:usage
echo Usage: upload-log.bat ^<logfile^> ^<label^> [run_id]
exit /b 1