Files
AetherForge/pack-usb.bat
AetherForge 2f528229f2 Improve portable USB pack and credentials-based tunnel launcher.
Expand pack-usb.bat to sync LAUNCH.bat, cloudflare assets, and data dirs while preserving operator state; align usb/LAUNCH.bat with credentials.json tunnel flow instead of a baked token.
2026-05-31 02:32:24 -07:00

175 lines
6.4 KiB
Batchfile

@echo off
setlocal EnableExtensions EnableDelayedExpansion
title AetherForge — Pack USB
cd /d "%~dp0"
set "ROOT=%CD%"
set "USB=%ROOT%\usb"
echo.
echo ================================================================
echo AetherForge — Pack Portable USB
echo ================================================================
echo.
echo Assembles a self-contained copy in: %USB%\
echo Copy that entire folder to a USB drive — nothing else needed.
echo.
:: ----------------------------------------------------------------
:: 0. Check prerequisites
:: ----------------------------------------------------------------
where go >nul 2>nul
if errorlevel 1 (
echo ERROR: Go not found on PATH.
echo Install from https://go.dev/dl/ or add it to PATH.
pause
exit /b 1
)
where npm >nul 2>nul
if errorlevel 1 (
echo WARNING: npm not found. Skipping frontend build.
set "SKIP_FRONTEND=1"
)
if not exist "%USB%" mkdir "%USB%"
:: ----------------------------------------------------------------
:: 1. Build the frontend when npm is available
:: ----------------------------------------------------------------
if not defined SKIP_FRONTEND (
echo [1/7] Building frontend...
cd "%ROOT%\server\web"
call npm install --silent
call npm run build
if errorlevel 1 (
echo ERROR: Frontend build failed.
cd "%ROOT%"
pause
exit /b 1
)
cd "%ROOT%"
echo [1/7] Frontend built.
) else (
echo [1/7] Skipped - npm not found.
)
:: ----------------------------------------------------------------
:: 2. Build AetherForge.exe for Windows amd64
:: ----------------------------------------------------------------
echo [2/7] Compiling AetherForge.exe...
cd "%ROOT%\server"
set "CGO_ENABLED=0"
set "GOOS=windows"
set "GOARCH=amd64"
go build -ldflags="-s -w" -o "%USB%\AetherForge.exe" .
if errorlevel 1 (
echo ERROR: Go build failed.
cd "%ROOT%"
pause
exit /b 1
)
cd "%ROOT%"
echo [2/7] AetherForge.exe ready.
:: ----------------------------------------------------------------
:: 3. Copy webroot - dashboard UI
:: ----------------------------------------------------------------
echo [3/7] Copying webroot...
if exist "%USB%\webroot" rd /s /q "%USB%\webroot"
if exist "%ROOT%\server\webroot" (
xcopy /e /i /q "%ROOT%\server\webroot" "%USB%\webroot" >nul
) else if exist "%ROOT%\server\web\dist" (
xcopy /e /i /q "%ROOT%\server\web\dist" "%USB%\webroot" >nul
) else (
echo ERROR: No webroot found. Run npm run build in server\web first.
pause
exit /b 1
)
echo [3/7] webroot copied.
:: ----------------------------------------------------------------
:: 4. Copy agent and fusion source - Forge needs these at runtime
:: ----------------------------------------------------------------
echo [4/7] Copying agent + fusion source...
if exist "%USB%\agent" rd /s /q "%USB%\agent"
if exist "%USB%\fusion" rd /s /q "%USB%\fusion"
xcopy /e /i /q /EXCLUDE:"%ROOT%\usb_pack_exclude.txt" "%ROOT%\agent" "%USB%\agent" >nul
xcopy /e /i /q /EXCLUDE:"%ROOT%\usb_pack_exclude.txt" "%ROOT%\fusion" "%USB%\fusion" >nul
echo [4/7] Source trees copied.
:: ----------------------------------------------------------------
:: 5. Launcher + docs (always sync from project root)
:: ----------------------------------------------------------------
echo [5/7] Syncing LAUNCH.bat, README, cloudflare...
copy /y "%ROOT%\LAUNCH.bat" "%USB%\LAUNCH.bat" >nul
if not exist "%USB%\README.txt" (
if exist "%ROOT%\usb\README.txt" copy /y "%ROOT%\usb\README.txt" "%USB%\README.txt" >nul
)
:: run.bat is a project-root marker used by some tooling
echo @echo off > "%USB%\run.bat"
echo rem AetherForge portable root marker >> "%USB%\run.bat"
if not exist "%USB%\cloudflare" mkdir "%USB%\cloudflare"
if exist "%ROOT%\usb\cloudflare\SETUP.txt" (
copy /y "%ROOT%\usb\cloudflare\SETUP.txt" "%USB%\cloudflare\SETUP.txt" >nul
)
if exist "%ROOT%\cloudflared-windows-amd64.msi" (
copy /y "%ROOT%\cloudflared-windows-amd64.msi" "%USB%\cloudflare\cloudflared-windows-amd64.msi" >nul
echo [5/7] cloudflared MSI bundled.
) else if exist "%ROOT%\usb\cloudflare\cloudflared-windows-amd64.msi" (
echo [5/7] cloudflared MSI already in usb\cloudflare\
) else (
echo [5/7] WARNING: No cloudflared MSI found. Tunnel auto-install skipped.
)
:: Preserve existing credentials.json if present (never overwrite operator tunnel)
if not exist "%USB%\cloudflare\credentials.json" (
if exist "%ROOT%\usb\cloudflare\credentials.json" (
copy /y "%ROOT%\usb\cloudflare\credentials.json" "%USB%\cloudflare\credentials.json" >nul
)
)
echo [5/7] Launcher synced.
:: ----------------------------------------------------------------
:: 6. Remove stale nested server mirror (not needed for portable)
:: ----------------------------------------------------------------
echo [6/7] Cleaning stale artifacts...
if exist "%USB%\server" rd /s /q "%USB%\server"
echo [6/7] Done.
:: ----------------------------------------------------------------
:: 7. Ensure data directories exist - preserve existing config and db
:: ----------------------------------------------------------------
echo [7/7] Ensuring data directories...
if not exist "%USB%\data" mkdir "%USB%\data"
if not exist "%USB%\data\builds" mkdir "%USB%\data\builds"
if not exist "%USB%\data\logs" mkdir "%USB%\data\logs"
if not exist "%USB%\data\blueprints" mkdir "%USB%\data\blueprints"
if not exist "%USB%\data\preps" mkdir "%USB%\data\preps"
if not exist "%USB%\data\spread-kits" mkdir "%USB%\data\spread-kits"
if not exist "%USB%\data\uploads" mkdir "%USB%\data\uploads"
if not exist "%USB%\data\cloudflare" mkdir "%USB%\data\cloudflare"
echo [7/7] data\ ready - existing config and db preserved.
:: ----------------------------------------------------------------
:: Summary
:: ----------------------------------------------------------------
echo.
echo ================================================================
echo USB pack complete!
echo.
echo Folder: %USB%\
echo.
dir /b "%USB%"
echo.
echo To use:
echo 1. Copy the entire usb\ folder to your USB drive
echo 2. Double-click LAUNCH.bat on any Windows PC
echo 3. Open http://localhost:8989
echo.
echo Your data\ and toolchain\ folders are preserved across repacks.
echo First launch without Go: LAUNCH.bat downloads toolchain\go\ once.
echo ================================================================
echo.
pause
endlocal