Harden run.bat: full pipeline, foreground logs, reliable launch.
Rebuild deps and server, kill stale process, open browser after delay, keep terminal open with pause on exit or failure. Add start.bat alias.
This commit is contained in:
216
run.bat
216
run.bat
@@ -1,18 +1,25 @@
|
|||||||
@echo off
|
@echo off
|
||||||
setlocal EnableExtensions
|
setlocal EnableExtensions EnableDelayedExpansion
|
||||||
title Crypto Miner Control Server
|
title AetherForge Control Server
|
||||||
cd /d "%~dp0"
|
cd /d "%~dp0"
|
||||||
|
set "ROOT=%CD%"
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ==================================================
|
echo ==============================================================
|
||||||
echo Crypto Miner Control Server Builder
|
echo AetherForge - Control Server Launcher
|
||||||
echo ==================================================
|
echo ==============================================================
|
||||||
|
echo This window stays open and shows live server logs.
|
||||||
|
echo Press Ctrl+C to stop the server.
|
||||||
|
echo ==============================================================
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
|
:: Common tool paths (Go/Node installs + user Go bin for garble)
|
||||||
|
set "PATH=C:\Program Files\Go\bin;%USERPROFILE%\go\bin;C:\Program Files\nodejs;%PATH%"
|
||||||
|
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
:: STEP 1: Auto-install Go if missing
|
:: STEP 1: Go
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
echo [1/5] Checking dependencies...
|
echo [1/5] Checking Go...
|
||||||
|
|
||||||
where go >nul 2>nul
|
where go >nul 2>nul
|
||||||
if errorlevel 1 goto install_go
|
if errorlevel 1 goto install_go
|
||||||
@@ -22,7 +29,6 @@ goto go_ready
|
|||||||
|
|
||||||
:install_go
|
:install_go
|
||||||
echo Go not found. Checking for existing installation...
|
echo Go not found. Checking for existing installation...
|
||||||
|
|
||||||
if exist "C:\Program Files\Go\bin\go.exe" (
|
if exist "C:\Program Files\Go\bin\go.exe" (
|
||||||
echo Found Go at C:\Program Files\Go\bin
|
echo Found Go at C:\Program Files\Go\bin
|
||||||
set "PATH=C:\Program Files\Go\bin;%PATH%"
|
set "PATH=C:\Program Files\Go\bin;%PATH%"
|
||||||
@@ -30,56 +36,46 @@ if exist "C:\Program Files\Go\bin\go.exe" (
|
|||||||
)
|
)
|
||||||
|
|
||||||
echo Downloading and installing Go...
|
echo Downloading and installing Go...
|
||||||
|
|
||||||
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
|
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
|
||||||
set "GO_ARCH=amd64"
|
set "GO_ARCH=amd64"
|
||||||
) else (
|
) else (
|
||||||
set "GO_ARCH=386"
|
set "GO_ARCH=386"
|
||||||
)
|
)
|
||||||
|
|
||||||
set "GO_VERSION=1.22.2"
|
set "GO_VERSION=1.22.2"
|
||||||
set "GO_URL=https://go.dev/dl/go%GO_VERSION%.windows-%GO_ARCH%.msi"
|
set "GO_URL=https://go.dev/dl/go%GO_VERSION%.windows-%GO_ARCH%.msi"
|
||||||
set "GO_MSI=%TEMP%\go-installer.msi"
|
set "GO_MSI=%TEMP%\go-installer.msi"
|
||||||
|
|
||||||
echo Downloading Go %GO_VERSION% for Windows %GO_ARCH%...
|
|
||||||
echo This may take a moment...
|
|
||||||
|
|
||||||
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GO_URL%' -OutFile '%GO_MSI%' }"
|
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GO_URL%' -OutFile '%GO_MSI%' }"
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo ERROR: Failed to download Go installer.
|
echo ERROR: Failed to download Go. Get it from https://go.dev/dl/
|
||||||
echo Please manually download from: https://go.dev/dl/
|
goto fatal_exit
|
||||||
pause
|
|
||||||
exit /b 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
echo Installing Go - administrator privileges may be required...
|
|
||||||
msiexec /i "%GO_MSI%" /quiet /norestart
|
msiexec /i "%GO_MSI%" /quiet /norestart
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo ERROR: Failed to install Go. Try running as Administrator.
|
echo ERROR: Go install failed. Run this script as Administrator.
|
||||||
pause
|
goto fatal_exit
|
||||||
exit /b 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
del "%GO_MSI%" 2>nul
|
del "%GO_MSI%" 2>nul
|
||||||
set "PATH=C:\Program Files\Go\bin;%PATH%"
|
set "PATH=C:\Program Files\Go\bin;%USERPROFILE%\go\bin;%PATH%"
|
||||||
set "PATH=%USERPROFILE%\go\bin;%PATH%"
|
echo Go installed.
|
||||||
echo Go installed successfully!
|
|
||||||
|
|
||||||
:go_ready
|
:go_ready
|
||||||
|
|
||||||
:: ============================================================
|
:: Garble (optional, for Forge obfuscation — failure is non-fatal)
|
||||||
:: STEP 1.5: Install Garble (Obfuscator) for Miner Builder
|
echo [1.5/5] Checking Garble (optional)...
|
||||||
:: ============================================================
|
|
||||||
echo [1.5/5] Checking for Garble obfuscator...
|
|
||||||
where garble >nul 2>nul
|
where garble >nul 2>nul
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo Garble not found. Installing via go install...
|
echo Installing garble via go install...
|
||||||
go install mvdan.cc/garble@latest
|
go install mvdan.cc/garble@latest
|
||||||
|
if errorlevel 1 echo WARNING: Garble install failed; Forge obfuscation may be unavailable.
|
||||||
)
|
)
|
||||||
|
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
:: STEP 2: Auto-install Node.js if missing (for frontend)
|
:: STEP 2: Node.js
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
|
echo [2/5] Checking Node.js...
|
||||||
|
|
||||||
where node >nul 2>nul
|
where node >nul 2>nul
|
||||||
if errorlevel 1 goto install_node
|
if errorlevel 1 goto install_node
|
||||||
echo Node.js found:
|
echo Node.js found:
|
||||||
@@ -88,7 +84,6 @@ goto node_ready
|
|||||||
|
|
||||||
:install_node
|
:install_node
|
||||||
echo Node.js not found. Checking for existing installation...
|
echo Node.js not found. Checking for existing installation...
|
||||||
|
|
||||||
if exist "C:\Program Files\nodejs\node.exe" (
|
if exist "C:\Program Files\nodejs\node.exe" (
|
||||||
echo Found Node.js at C:\Program Files\nodejs
|
echo Found Node.js at C:\Program Files\nodejs
|
||||||
set "PATH=C:\Program Files\nodejs;%PATH%"
|
set "PATH=C:\Program Files\nodejs;%PATH%"
|
||||||
@@ -96,160 +91,151 @@ if exist "C:\Program Files\nodejs\node.exe" (
|
|||||||
)
|
)
|
||||||
|
|
||||||
echo Downloading and installing Node.js...
|
echo Downloading and installing Node.js...
|
||||||
|
|
||||||
set "NODE_VERSION=20.12.2"
|
set "NODE_VERSION=20.12.2"
|
||||||
set "NODE_URL=https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-x64.msi"
|
set "NODE_URL=https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-x64.msi"
|
||||||
set "NODE_MSI=%TEMP%\node-installer.msi"
|
set "NODE_MSI=%TEMP%\node-installer.msi"
|
||||||
|
|
||||||
echo Downloading Node.js v%NODE_VERSION%...
|
|
||||||
echo This may take a moment...
|
|
||||||
|
|
||||||
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%NODE_URL%' -OutFile '%NODE_MSI%' }"
|
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%NODE_URL%' -OutFile '%NODE_MSI%' }"
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo WARNING: Failed to download Node.js. Frontend will not be built.
|
echo WARNING: Node.js download failed. Frontend build will be skipped.
|
||||||
echo You can manually download from: https://nodejs.org/
|
|
||||||
set "SKIP_FRONTEND=1"
|
set "SKIP_FRONTEND=1"
|
||||||
goto node_ready
|
goto node_ready
|
||||||
)
|
)
|
||||||
|
|
||||||
echo Installing Node.js - administrator privileges may be required...
|
|
||||||
msiexec /i "%NODE_MSI%" /quiet /norestart
|
msiexec /i "%NODE_MSI%" /quiet /norestart
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo WARNING: Failed to install Node.js. Frontend will not be built.
|
echo WARNING: Node.js install failed. Frontend build will be skipped.
|
||||||
set "SKIP_FRONTEND=1"
|
set "SKIP_FRONTEND=1"
|
||||||
goto node_ready
|
goto node_ready
|
||||||
)
|
)
|
||||||
|
|
||||||
set "PATH=C:\Program Files\nodejs;%PATH%"
|
set "PATH=C:\Program Files\nodejs;%PATH%"
|
||||||
del "%NODE_MSI%" 2>nul
|
del "%NODE_MSI%" 2>nul
|
||||||
echo Node.js installed successfully!
|
echo Node.js installed.
|
||||||
|
|
||||||
:node_ready
|
:node_ready
|
||||||
|
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
:: STEP 3: Create data directories
|
:: STEP 3: Data directories
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
echo [2/5] Creating data directories...
|
echo [3/5] Preparing data directories...
|
||||||
if not exist "data\builds" mkdir "data\builds"
|
if not exist "data\builds" mkdir "data\builds"
|
||||||
if not exist "data\logs" mkdir "data\logs"
|
if not exist "data\logs" mkdir "data\logs"
|
||||||
if not exist "data\blueprints" mkdir "data\blueprints"
|
if not exist "data\blueprints" mkdir "data\blueprints"
|
||||||
if not exist "data\preps" mkdir "data\preps"
|
if not exist "data\preps" mkdir "data\preps"
|
||||||
if not exist "bin" mkdir "bin"
|
if not exist "bin" mkdir "bin"
|
||||||
echo Created: data\builds, data\logs, data\blueprints, data\preps, bin
|
echo OK: data\ and bin\
|
||||||
|
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
:: STEP 4: Build frontend
|
:: STEP 4: Frontend
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
if defined SKIP_FRONTEND goto skip_frontend
|
if defined SKIP_FRONTEND goto skip_frontend
|
||||||
echo [3/5] Building frontend dashboard...
|
echo [4/5] Building dashboard (server\web)...
|
||||||
echo Running npm install and npm run build in server\web\
|
cd /d "%ROOT%\server\web"
|
||||||
cd server\web
|
|
||||||
if not exist "node_modules" (
|
if not exist "node_modules" (
|
||||||
echo Installing npm dependencies...
|
echo npm install...
|
||||||
call npm install
|
call npm install
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo ERROR: npm install failed
|
cd /d "%ROOT%"
|
||||||
cd ..\..
|
echo ERROR: npm install failed.
|
||||||
pause
|
goto fatal_exit
|
||||||
exit /b 1
|
|
||||||
)
|
)
|
||||||
echo npm install completed successfully.
|
|
||||||
)
|
)
|
||||||
echo Building frontend with Vite...
|
echo npm run build...
|
||||||
call npm run build
|
call npm run build
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo ERROR: Frontend build failed
|
cd /d "%ROOT%"
|
||||||
cd ..\..
|
echo ERROR: Frontend build failed.
|
||||||
pause
|
goto fatal_exit
|
||||||
exit /b 1
|
|
||||||
) else (
|
|
||||||
echo Frontend built successfully: server\web\dist
|
|
||||||
)
|
)
|
||||||
cd ..\..
|
cd /d "%ROOT%"
|
||||||
|
echo Frontend built: server\web\dist
|
||||||
goto frontend_done
|
goto frontend_done
|
||||||
|
|
||||||
:skip_frontend
|
:skip_frontend
|
||||||
echo [3/5] Skipping frontend build - Node.js not available
|
echo [4/5] Skipping frontend build (Node.js unavailable)
|
||||||
|
if not exist "server\web\dist\index.html" (
|
||||||
|
echo WARNING: No server\web\dist\index.html — dashboard may not load.
|
||||||
|
)
|
||||||
|
|
||||||
:frontend_done
|
:frontend_done
|
||||||
|
|
||||||
:: Copy frontend to webroot for server
|
|
||||||
if exist "server\web\dist\index.html" (
|
if exist "server\web\dist\index.html" (
|
||||||
if not exist "server\webroot" mkdir "server\webroot"
|
if not exist "server\webroot" mkdir "server\webroot"
|
||||||
xcopy /E /I /Y "server\web\dist\*" "server\webroot\" >nul
|
xcopy /E /I /Y /Q "server\web\dist\*" "server\webroot\" >nul
|
||||||
echo Copied dashboard to server\webroot
|
echo Copied dashboard to server\webroot
|
||||||
)
|
)
|
||||||
|
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
:: STEP 5: Build server
|
:: STEP 5: Server binary
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
echo [4/5] Building server...
|
echo [5/5] Building control server...
|
||||||
echo Running go build in server\...
|
cd /d "%ROOT%\server"
|
||||||
|
|
||||||
cd server
|
|
||||||
|
|
||||||
echo Downloading Go dependencies...
|
|
||||||
go mod download
|
go mod download
|
||||||
if errorlevel 1 (
|
if errorlevel 1 echo WARNING: go mod download had issues; continuing...
|
||||||
echo WARNING: go mod download failed, trying build anyway...
|
echo go build...
|
||||||
)
|
|
||||||
|
|
||||||
echo Compiling server binary...
|
|
||||||
go build -ldflags="-s -w" -o "..\bin\miner-server.exe" .
|
go build -ldflags="-s -w" -o "..\bin\miner-server.exe" .
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo ERROR: Build failed
|
cd /d "%ROOT%"
|
||||||
cd ..
|
echo ERROR: Server build failed.
|
||||||
pause
|
goto fatal_exit
|
||||||
exit /b 1
|
|
||||||
)
|
)
|
||||||
cd ..
|
cd /d "%ROOT%"
|
||||||
echo Server built successfully: bin\miner-server.exe
|
|
||||||
|
if not exist "bin\miner-server.exe" (
|
||||||
|
echo ERROR: bin\miner-server.exe was not created.
|
||||||
|
goto fatal_exit
|
||||||
|
)
|
||||||
|
echo Server binary: bin\miner-server.exe
|
||||||
|
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
:: LAUNCH
|
:: LAUNCH (foreground — logs stay in this window)
|
||||||
:: ============================================================
|
:: ============================================================
|
||||||
echo [5/5] Starting server on port 8989...
|
|
||||||
echo.
|
echo.
|
||||||
|
echo Stopping any previous miner-server.exe...
|
||||||
|
taskkill /F /IM miner-server.exe >nul 2>nul
|
||||||
|
timeout /t 1 /nobreak >nul
|
||||||
|
|
||||||
set "LAN_IP=localhost"
|
set "LAN_IP=localhost"
|
||||||
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command "(Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' -and $_.PrefixOrigin -ne 'WellKnown' } | Select-Object -First 1 -ExpandProperty IPAddress)"`) do set "LAN_IP=%%I"
|
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command "(Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' -and $_.PrefixOrigin -ne 'WellKnown' } | Select-Object -First 1 -ExpandProperty IPAddress) 2>$null"`) do set "LAN_IP=%%I"
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ==============================================================
|
echo ==============================================================
|
||||||
echo SERVER IS NOW LIVE
|
echo STARTING CONTROL SERVER
|
||||||
echo ==============================================================
|
echo ==============================================================
|
||||||
|
echo Dashboard: http://localhost:8989
|
||||||
|
echo LAN: http://%LAN_IP%:8989
|
||||||
|
echo Agents WS: ws://%LAN_IP%:8989/ws/agent
|
||||||
|
echo Data: %ROOT%\data\
|
||||||
echo.
|
echo.
|
||||||
echo Dashboard URL: http://0.0.0.0:8989
|
echo Live logs appear below. Ctrl+C stops the server.
|
||||||
echo LAN Access: http://%LAN_IP%:8989
|
|
||||||
echo Local: http://localhost:8989
|
|
||||||
echo.
|
|
||||||
echo WebSocket agents: ws://%LAN_IP%:8989/ws/agent
|
|
||||||
echo WebSocket dash: ws://%LAN_IP%:8989/ws/dashboard
|
|
||||||
echo.
|
|
||||||
echo Quick Start:
|
|
||||||
echo 1. Open Dashboard in your browser
|
|
||||||
echo 2. Go to Calibrate - configure pool and wallet
|
|
||||||
echo 3. Go to Forge - build your miner installer .exe
|
|
||||||
echo 4. Run that .exe on each Windows machine
|
|
||||||
echo.
|
|
||||||
echo Data Directory: %CD%\data\
|
|
||||||
echo Config File: %CD%\data\config.json
|
|
||||||
echo Blueprints: %CD%\data\blueprints\
|
|
||||||
echo.
|
|
||||||
echo Press Ctrl+C in this window to stop the server
|
|
||||||
echo ==============================================================
|
echo ==============================================================
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
start http://localhost:8989
|
:: Open browser after a short delay (server starts in this window)
|
||||||
|
start "" cmd /c "timeout /t 3 /nobreak >nul && start http://localhost:8989/"
|
||||||
|
|
||||||
:: If an old server instance is running, stop it first to avoid bind errors.
|
echo [Server] miner-server.exe -port 8989 -data "%ROOT%\data"
|
||||||
taskkill /F /IM miner-server.exe >nul 2>nul
|
|
||||||
|
|
||||||
echo [Server] Starting miner-server.exe on 0.0.0.0:8989...
|
|
||||||
echo [Server] Log output below - Ctrl+C to stop:
|
|
||||||
echo.
|
echo.
|
||||||
.\bin\miner-server.exe -port 8989 -data ".\data"
|
|
||||||
|
.\bin\miner-server.exe -port 8989 -data "%ROOT%\data"
|
||||||
|
set "EXITCODE=!ERRORLEVEL!"
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo [Server] Server stopped.
|
if "!EXITCODE!"=="0" (
|
||||||
|
echo [Server] Stopped normally.
|
||||||
|
) else (
|
||||||
|
echo [Server] Exited with code !EXITCODE!.
|
||||||
|
echo If port 8989 was in use, close other miner-server windows and run again.
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
goto end_pause
|
||||||
|
|
||||||
|
:fatal_exit
|
||||||
|
echo.
|
||||||
|
echo ==============================================================
|
||||||
|
echo LAUNCH FAILED — fix the errors above and run run.bat again.
|
||||||
|
echo ==============================================================
|
||||||
|
echo.
|
||||||
|
|
||||||
|
:end_pause
|
||||||
pause
|
pause
|
||||||
|
endlocal
|
||||||
|
|||||||
Reference in New Issue
Block a user