Make built exe a one-run Windows installer pointing at LAN dashboard.

Install copies miner to AppData, registers autostart, relaunches silently, and builder defaults server URL to local IP.
This commit is contained in:
drjones
2026-05-26 22:52:47 -07:00
parent 6c42f2b600
commit 6241dfd556
10 changed files with 375 additions and 59 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"log"
"os"
"path/filepath"
"crypto-miner-agent/client"
"crypto-miner-agent/config"
@@ -12,6 +13,7 @@ import (
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
cfg := config.Load()
setupLogging(cfg)
if cfg.Wallet == "" {
log.Fatal("wallet address is required in built-in configuration")
@@ -20,19 +22,20 @@ func main() {
log.Fatal("server URL is required in built-in configuration")
}
installed, err := deploy.InstallIfNeeded(cfg)
if err != nil {
log.Fatalf("[installer] failed: %v", err)
}
if installed {
log.Printf("[installer] installed worker=%s to permanent location and started miner", cfg.WorkerName)
return
}
if err := deploy.SetProcessPriority(cfg.CPUPriority); err != nil {
log.Printf("[agent] could not set CPU priority: %v", err)
}
if cfg.AutoStart {
if exe, err := deploy.CurrentExecutable(); err == nil {
if err := deploy.ConfigureAutoStart(exe, true); err != nil {
log.Printf("[agent] auto-start setup failed: %v", err)
}
}
}
log.Printf("[agent] starting worker=%s build=%s server=%s threads=%d",
log.Printf("[agent] running worker=%s build=%s server=%s threads=%d",
cfg.WorkerName, cfg.BuildID, cfg.ServerURL, cfg.Threads)
agent := client.NewAgentClient(cfg)
@@ -41,12 +44,25 @@ func main() {
}
}
func init() {
// Hide console when built with -H windowsgui by redirecting logs to file if needed.
func setupLogging(cfg config.RuntimeConfig) {
if os.Getenv("MINER_LOG_FILE") != "" {
f, err := os.OpenFile(os.Getenv("MINER_LOG_FILE"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err == nil {
log.SetOutput(f)
}
redirectLog(os.Getenv("MINER_LOG_FILE"))
return
}
installDir, err := deploy.InstallDir(cfg.WorkerName, cfg.BuildID)
if err != nil {
return
}
redirectLog(filepath.Join(installDir, "miner.log"))
}
func redirectLog(path string) {
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return
}
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err == nil {
log.SetOutput(f)
}
}