Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Operators double-click LAUNCH for git pull, npm build, data prep, cloudflared, and AetherForge or dev miner-server; devrun shares launch-prep.
293 lines
8.9 KiB
Batchfile
293 lines
8.9 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions EnableDelayedExpansion
|
|
title AetherForge Control Deck
|
|
cd /d "%~dp0"
|
|
set "REPO=%CD%"
|
|
|
|
echo.
|
|
echo ================================================================
|
|
echo AetherForge - One-Click Launch
|
|
echo ================================================================
|
|
echo Folder: %REPO%
|
|
echo.
|
|
|
|
set "PREP=%REPO%\scripts\launch-prep.bat"
|
|
if not exist "%PREP%" set "PREP=%REPO%\..\scripts\launch-prep.bat"
|
|
if exist "%PREP%" (
|
|
call "%PREP%" "%REPO%"
|
|
if errorlevel 1 (
|
|
echo.
|
|
echo LAUNCH prep failed - fix errors above and retry.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
) else (
|
|
echo [Prep] launch-prep.bat not found - skipping pull/UI build.
|
|
)
|
|
|
|
if /i "%AF_LAUNCH_DRY_RUN%"=="1" (
|
|
echo.
|
|
echo [Dry run] Prep steps OK - not starting tunnel or server.
|
|
pause
|
|
exit /b 0
|
|
)
|
|
|
|
:: Portable deck root = folder that contains AetherForge.exe (repo usb\ or copied USB drive)
|
|
set "ROOT="
|
|
if exist "%CD%\AetherForge.exe" (
|
|
set "ROOT=!CD!"
|
|
) else if exist "%CD%\usb\AetherForge.exe" (
|
|
cd /d "%CD%\usb"
|
|
set "ROOT=!CD!"
|
|
)
|
|
|
|
if defined ROOT if exist "%ROOT%\AetherForge.exe" goto portable_deck
|
|
|
|
:: No portable binary - dev control server from repo
|
|
goto dev_server_launch
|
|
|
|
:portable_deck
|
|
|
|
if not exist "%ROOT%\AetherForge.exe" (
|
|
echo ERROR: AetherForge.exe missing in %ROOT%
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo ================================================================
|
|
echo AetherForge - Portable Control Deck
|
|
echo ================================================================
|
|
echo Deck: %ROOT%
|
|
echo.
|
|
|
|
:: ----------------------------------------------------------------
|
|
:: 1. Locate Go - prefer bundled toolchain, fall back to system Go
|
|
:: ----------------------------------------------------------------
|
|
set "BUNDLED_GO=%ROOT%\toolchain\go\bin\go.exe"
|
|
set "GO_BIN="
|
|
|
|
if exist "%ROOT%\toolchain\go" if not exist "%BUNDLED_GO%" (
|
|
echo [Go] Incomplete toolchain folder - removing broken install...
|
|
rd /s /q "%ROOT%\toolchain\go" 2>nul
|
|
)
|
|
|
|
if exist "%BUNDLED_GO%" (
|
|
echo [Go] Using bundled toolchain: %ROOT%\toolchain\go
|
|
set "GO_BIN=%ROOT%\toolchain\go\bin\go.exe"
|
|
set "GOROOT=%ROOT%\toolchain\go"
|
|
set "PATH=%ROOT%\toolchain\go\bin;%ROOT%\toolchain\gopath\bin;%PATH%"
|
|
goto go_ready
|
|
)
|
|
|
|
where go >nul 2>nul
|
|
if not errorlevel 1 (
|
|
echo [Go] Using system Go installation.
|
|
set "GO_BIN=go"
|
|
goto go_ready
|
|
)
|
|
|
|
echo.
|
|
echo [Go] Go not found - Forge obfuscation tools unavailable. Running server without them.
|
|
echo.
|
|
goto server_launch
|
|
|
|
:go_ready
|
|
|
|
set "GOPATH=%ROOT%\toolchain\gopath"
|
|
set "GOMODCACHE=%ROOT%\toolchain\gopath\pkg\mod"
|
|
set "GOCACHE=%ROOT%\toolchain\gocache"
|
|
set "GOENV=off"
|
|
|
|
if /i not "%AF_INSTALL_TOOLS%"=="0" (
|
|
if not exist "%ROOT%\toolchain\gopath\bin\garble.exe" (
|
|
echo [Tools] Installing garble...
|
|
"%GO_BIN%" install mvdan.cc/garble@latest
|
|
if errorlevel 1 echo [Tools] WARN: garble install failed.
|
|
)
|
|
|
|
if not exist "%ROOT%\toolchain\gopath\bin\go-winres.exe" (
|
|
echo [Tools] Installing go-winres...
|
|
"%GO_BIN%" install github.com/tc-hib/go-winres@v0.3.1
|
|
if errorlevel 1 echo [Tools] WARN: go-winres install failed.
|
|
)
|
|
) else (
|
|
echo [Tools] Auto-install disabled ^(AF_INSTALL_TOOLS=0^).
|
|
)
|
|
|
|
:server_launch
|
|
|
|
echo.
|
|
echo Ensuring data directories...
|
|
if not exist "%ROOT%\data\builds" mkdir "%ROOT%\data\builds"
|
|
if not exist "%ROOT%\data\logs" mkdir "%ROOT%\data\logs"
|
|
if not exist "%ROOT%\data\spread-kits" mkdir "%ROOT%\data\spread-kits"
|
|
if not exist "%ROOT%\data\uploads" mkdir "%ROOT%\data\uploads"
|
|
if not exist "%ROOT%\data\blueprints" mkdir "%ROOT%\data\blueprints"
|
|
if not exist "%ROOT%\data\preps" mkdir "%ROOT%\data\preps"
|
|
|
|
set "SERVER_PORT=8989"
|
|
set "CONFIG_FILE=%ROOT%\data\config.json"
|
|
if exist "%CONFIG_FILE%" (
|
|
for /f "usebackq delims=" %%P in (`powershell -NoProfile -Command "try { $j = Get-Content -Raw '%CONFIG_FILE%' | ConvertFrom-Json; if ($j.port) { $j.port } } catch { }"`) do (
|
|
if not "%%P"=="" set "SERVER_PORT=%%P"
|
|
)
|
|
)
|
|
for /f "tokens=2 delims=:" %%I in ('ipconfig ^| findstr /i "IPv4" ^| findstr /v "127.0.0.1"') do (
|
|
set "LAN_IP=%%I"
|
|
goto lan_done
|
|
)
|
|
set "LAN_IP=localhost"
|
|
:lan_done
|
|
set "LAN_IP=%LAN_IP: =%"
|
|
|
|
echo Stopping stale processes...
|
|
taskkill /F /IM AetherForge.exe >nul 2>nul
|
|
taskkill /F /IM cloudflared.exe >nul 2>nul
|
|
ping -n 2 127.0.0.1 >nul
|
|
|
|
echo.
|
|
echo ================================================================
|
|
echo STARTING CONTROL DECK
|
|
echo ================================================================
|
|
echo Local: http://localhost:%SERVER_PORT%
|
|
echo LAN: http://%LAN_IP%:%SERVER_PORT%
|
|
echo Data: %ROOT%\data\
|
|
echo.
|
|
echo Login accounts: admin + comrade ^(passwords below after start^).
|
|
echo Press Ctrl+C to stop.
|
|
echo ================================================================
|
|
echo.
|
|
|
|
echo Starting tunnel...
|
|
set "CF_SCRIPT=%ROOT%\scripts\usb-start-cloudflared.ps1"
|
|
if not exist "%CF_SCRIPT%" set "CF_SCRIPT=%ROOT%\..\scripts\usb-start-cloudflared.ps1"
|
|
if exist "%CF_SCRIPT%" (
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%CF_SCRIPT%" -DeckRoot "%ROOT%"
|
|
) else (
|
|
echo [Tunnel] WARNING: scripts\usb-start-cloudflared.ps1 missing - repack usb folder.
|
|
)
|
|
echo.
|
|
|
|
cd /d "%ROOT%"
|
|
|
|
start "" powershell -NoProfile -WindowStyle Hidden -Command "Start-Sleep -Seconds 3; Start-Process 'http://localhost:%SERVER_PORT%/'"
|
|
|
|
echo Starting server...
|
|
set "AF_TUNNEL_EXTERNAL=1"
|
|
"%ROOT%\AetherForge.exe" -data "%ROOT%\data"
|
|
set "EC=!ERRORLEVEL!"
|
|
|
|
call :cleanup_tunnel "%ROOT%"
|
|
goto server_stopped
|
|
|
|
:dev_server_launch
|
|
echo.
|
|
echo No AetherForge.exe - starting dev control server ^(repo^).
|
|
echo ^(Run pack-usb.bat for portable USB bundle.^)
|
|
echo.
|
|
|
|
set "PATH=C:\Program Files\Go\bin;%USERPROFILE%\go\bin;C:\Program Files\nodejs;%PATH%"
|
|
set "DATA=%REPO%\data"
|
|
set "DECK=%REPO%"
|
|
if exist "%REPO%\usb\tools\cloudflared.exe" set "DECK=%REPO%\usb"
|
|
if exist "%REPO%\usb\data" if not exist "%DECK%\data" set "DECK=%REPO%\usb"
|
|
|
|
echo Ensuring data directories...
|
|
if not exist "%DATA%\builds" mkdir "%DATA%\builds"
|
|
if not exist "%DATA%\logs" mkdir "%DATA%\logs"
|
|
if not exist "%DATA%\spread-kits" mkdir "%DATA%\spread-kits"
|
|
if not exist "%DATA%\uploads" mkdir "%DATA%\uploads"
|
|
if not exist "%DATA%\blueprints" mkdir "%DATA%\blueprints"
|
|
if not exist "%DATA%\preps" mkdir "%DATA%\preps"
|
|
if not exist "%REPO%\bin" mkdir "%REPO%\bin"
|
|
|
|
set "SERVER_PORT=8989"
|
|
set "CONFIG_FILE=%DATA%\config.json"
|
|
if exist "%CONFIG_FILE%" (
|
|
for /f "usebackq delims=" %%P in (`powershell -NoProfile -Command "try { $j = Get-Content -Raw '%CONFIG_FILE%' | ConvertFrom-Json; if ($j.port) { $j.port } } catch { }"`) do (
|
|
if not "%%P"=="" set "SERVER_PORT=%%P"
|
|
)
|
|
)
|
|
set "LAN_IP=localhost"
|
|
|
|
echo Stopping stale processes...
|
|
taskkill /F /IM miner-server.exe >nul 2>nul
|
|
taskkill /F /IM AetherForge.exe >nul 2>nul
|
|
taskkill /F /IM cloudflared.exe >nul 2>nul
|
|
ping -n 2 127.0.0.1 >nul
|
|
|
|
where go >nul 2>nul
|
|
if errorlevel 1 (
|
|
echo ERROR: Go not found - install from https://go.dev/dl/ or use pack-usb.bat
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%REPO%\bin\miner-server.exe" (
|
|
echo Building control server...
|
|
cd /d "%REPO%\server"
|
|
go mod download >nul 2>nul
|
|
go build -ldflags="-s -w" -o "..\bin\miner-server.exe" .
|
|
if errorlevel 1 (
|
|
cd /d "%REPO%"
|
|
echo ERROR: Server build failed.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
cd /d "%REPO%"
|
|
)
|
|
|
|
echo.
|
|
echo ================================================================
|
|
echo STARTING CONTROL SERVER ^(dev^)
|
|
echo ================================================================
|
|
echo Dashboard: http://localhost:%SERVER_PORT%
|
|
echo Data: %DATA%\
|
|
echo ================================================================
|
|
echo.
|
|
|
|
echo Starting tunnel...
|
|
set "CF_SCRIPT=%REPO%\scripts\usb-start-cloudflared.ps1"
|
|
if not exist "%CF_SCRIPT%" set "CF_SCRIPT=%DECK%\scripts\usb-start-cloudflared.ps1"
|
|
if exist "%CF_SCRIPT%" (
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%CF_SCRIPT%" -DeckRoot "%DECK%"
|
|
) else (
|
|
echo [Tunnel] WARNING: usb-start-cloudflared.ps1 not found.
|
|
)
|
|
echo.
|
|
|
|
start "" powershell -NoProfile -WindowStyle Hidden -Command "Start-Sleep -Seconds 3; Start-Process 'http://localhost:%SERVER_PORT%/'"
|
|
|
|
echo Starting server...
|
|
cd /d "%REPO%"
|
|
set "AF_TUNNEL_EXTERNAL=1"
|
|
"%REPO%\bin\miner-server.exe" -data "%DATA%"
|
|
set "EC=!ERRORLEVEL!"
|
|
|
|
call :cleanup_tunnel "%DECK%"
|
|
goto server_stopped
|
|
|
|
:cleanup_tunnel
|
|
set "TROOT=%~1"
|
|
if exist "%TROOT%\data\cloudflared.pid" (
|
|
for /f "usebackq" %%P in ("%TROOT%\data\cloudflared.pid") do (
|
|
taskkill /F /PID %%P >nul 2>nul
|
|
)
|
|
del "%TROOT%\data\cloudflared.pid" 2>nul
|
|
)
|
|
taskkill /F /IM cloudflared.exe >nul 2>nul
|
|
exit /b 0
|
|
|
|
:server_stopped
|
|
echo.
|
|
if "!EC!"=="0" (
|
|
echo [Server] Stopped normally.
|
|
) else (
|
|
echo [Server] Exited with code !EC!.
|
|
echo If port %SERVER_PORT% is in use, close other server windows and retry.
|
|
)
|
|
|
|
echo.
|
|
pause
|
|
endlocal
|