Implement Windows agent with RandomX mining and WebSocket fleet reporting, wire dashboard settings into the builder with saved exe paths, and add project README.
189 lines
6.5 KiB
Batchfile
189 lines
6.5 KiB
Batchfile
@echo off
|
|
title Crypto Miner Control Server
|
|
cd /d "%~dp0"
|
|
|
|
echo.
|
|
echo ╔══════════════════════════════════════════════════╗
|
|
echo ║ Crypto Miner Control Server Builder ║
|
|
echo ╚══════════════════════════════════════════════════╝
|
|
echo.
|
|
|
|
:: ============================================================
|
|
:: STEP 1: Auto-install Go if missing
|
|
:: ============================================================
|
|
echo [1/5] Checking dependencies...
|
|
|
|
where go >nul 2>nul
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo Go not found. Downloading and installing Go...
|
|
|
|
:: Detect architecture
|
|
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
|
|
set GO_ARCH=amd64
|
|
) else (
|
|
set GO_ARCH=386
|
|
)
|
|
|
|
set GO_VERSION=1.22.2
|
|
set GO_URL=https://go.dev/dl/go%GO_VERSION%.windows-%GO_ARCH%.msi
|
|
set GO_MSI=%TEMP%\go-installer.msi
|
|
|
|
echo Downloading Go %GO_VERSION% for Windows %GO_ARCH%...
|
|
echo (This may take a moment...)
|
|
|
|
:: Download using PowerShell (built into Windows)
|
|
powershell -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GO_URL%' -OutFile '%GO_MSI%' }"
|
|
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo ERROR: Failed to download Go installer.
|
|
echo Please manually download from: https://go.dev/dl/
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo Installing Go (this may require administrator privileges)...
|
|
msiexec /i "%GO_MSI%" /quiet /norestart
|
|
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo ERROR: Failed to install Go. Try running as Administrator.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
:: Clean up installer
|
|
del "%GO_MSI%" 2>nul
|
|
|
|
:: Add Go to PATH for this session
|
|
set PATH=%PATH%;C:\Program Files\Go\bin
|
|
set PATH=%PATH%;%USERPROFILE%\go\bin
|
|
|
|
echo Go installed successfully!
|
|
) else (
|
|
echo Go found:
|
|
call go version
|
|
)
|
|
|
|
:: ============================================================
|
|
:: STEP 2: Auto-install Node.js if missing (for frontend)
|
|
:: ============================================================
|
|
where node >nul 2>nul
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo Node.js not found. Downloading and installing Node.js...
|
|
|
|
set NODE_VERSION=20.12.2
|
|
set NODE_URL=https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-x64.msi
|
|
set NODE_MSI=%TEMP%\node-installer.msi
|
|
|
|
echo Downloading Node.js v%NODE_VERSION%...
|
|
echo (This may take a moment...)
|
|
|
|
powershell -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%NODE_URL%' -OutFile '%NODE_MSI%' }"
|
|
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo WARNING: Failed to download Node.js. Frontend will not be built.
|
|
echo You can manually download from: https://nodejs.org/
|
|
set SKIP_FRONTEND=1
|
|
) else (
|
|
echo Installing Node.js (this may require administrator privileges)...
|
|
msiexec /i "%NODE_MSI%" /quiet /norestart
|
|
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo WARNING: Failed to install Node.js. Frontend will not be built.
|
|
set SKIP_FRONTEND=1
|
|
) else (
|
|
:: Add Node to PATH for this session
|
|
set PATH=%PATH%;C:\Program Files\nodejs
|
|
|
|
del "%NODE_MSI%" 2>nul
|
|
echo Node.js installed successfully!
|
|
)
|
|
)
|
|
) else (
|
|
echo Node.js found:
|
|
call node --version
|
|
)
|
|
|
|
:: ============================================================
|
|
:: STEP 3: Create data directories
|
|
:: ============================================================
|
|
echo [2/5] Creating data directories...
|
|
if not exist "data\builds" mkdir "data\builds"
|
|
if not exist "data\logs" mkdir "data\logs"
|
|
echo Done.
|
|
|
|
:: ============================================================
|
|
:: STEP 4: Build frontend
|
|
:: ============================================================
|
|
if "%SKIP_FRONTEND%"=="" (
|
|
echo [3/5] Building frontend dashboard...
|
|
cd server\web
|
|
if not exist "node_modules" (
|
|
echo Installing npm dependencies...
|
|
call npm install
|
|
)
|
|
call npm run build
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo WARNING: Frontend build failed, server will run without dashboard.
|
|
) else (
|
|
echo Frontend built: server\web\dist
|
|
)
|
|
cd ..\..
|
|
|
|
:: Copy frontend dist to server's webroot directory
|
|
if exist "server\web\dist" (
|
|
if not exist "server\webroot" mkdir "server\webroot"
|
|
xcopy /E /I /Y "server\web\dist\*" "server\webroot\" >nul
|
|
echo Frontend files copied to server\webroot
|
|
)
|
|
) else (
|
|
echo [3/5] Skipping frontend build (Node.js not available)
|
|
)
|
|
|
|
:: ============================================================
|
|
:: STEP 5: Build server
|
|
:: ============================================================
|
|
echo [4/5] Building server...
|
|
cd server
|
|
|
|
:: Download Go module dependencies
|
|
echo Downloading Go dependencies...
|
|
go mod download
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo WARNING: go mod download failed, trying build anyway...
|
|
)
|
|
|
|
go build -ldflags="-s -w" -o "..\bin\miner-server.exe" .
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo ERROR: Build failed
|
|
pause
|
|
exit /b 1
|
|
)
|
|
cd ..
|
|
echo Server built: bin\miner-server.exe
|
|
|
|
:: ============================================================
|
|
:: LAUNCH
|
|
:: ============================================================
|
|
echo [5/5] Starting server on port 8989...
|
|
echo.
|
|
echo ╔══════════════════════════════════════════════════╗
|
|
echo ║ Crypto Miner Control Server ║
|
|
echo ║ ║
|
|
echo ║ Dashboard: http://localhost:8989 ║
|
|
echo ║ WebSocket: ws://localhost:8989/ws/agent ║
|
|
echo ║ ║
|
|
echo ║ Data: %CD%\data\ ║
|
|
echo ║ Config: %CD%\data\config.json ║
|
|
echo ║ ║
|
|
echo ║ Press Ctrl+C to stop the server ║
|
|
echo ╚══════════════════════════════════════════════════╝
|
|
echo.
|
|
|
|
:: Launch browser
|
|
start http://localhost:8989
|
|
|
|
:: Run server
|
|
.\bin\miner-server.exe -port 8989 -data ".\data"
|
|
|
|
pause
|