-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlaunch_worker.ps1
More file actions
94 lines (80 loc) · 3.48 KB
/
launch_worker.ps1
File metadata and controls
94 lines (80 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<#
.SYNOPSIS
Fractum Worker Launcher (Production)
- Silent startup.
- No debug logs.
- Launches worker in its own window.
#>
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
# --- Configuration ---
$ManagerUrl = "https://encode.fractumseraph.net/"
$WorkerUrl = "$($ManagerUrl)dl/worker"
$ConfigFile = "worker_config.json"
$Config = $null
function Show-Error($msg) {
[System.Windows.Forms.MessageBox]::Show($msg, "Fractum Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
# --- 1. Load or Create Config ---
if (Test-Path $ConfigFile) {
try {
$rawJson = Get-Content $ConfigFile -Raw
if ([string]::IsNullOrWhiteSpace($rawJson)) { throw "Empty File" }
$Config = $rawJson | ConvertFrom-Json
} catch {
Remove-Item $ConfigFile -ErrorAction SilentlyContinue
}
}
if (-not $Config) {
$defUser = "Anonymous"
$uPrompt = "Please enter the USERNAME of the person running the program.`n(e.g. 'FractumSeraph')`n`n[Click Cancel to Quit]"
$uInput = [Microsoft.VisualBasic.Interaction]::InputBox($uPrompt, "Fractum Setup (1/2)", $defUser)
if ($uInput -eq "") { exit }
$defWorker = "Node-" + (Get-Random -Minimum 1000 -Maximum 9999)
$wPrompt = "Please enter a name for THIS COMPUTER.`n(e.g. 'LivingRoom-PC')`n`n[Click Cancel to Quit]"
$wInput = [Microsoft.VisualBasic.Interaction]::InputBox($wPrompt, "Fractum Setup (2/2)", $defWorker)
if ($wInput -eq "") { exit }
$Config = @{ username = $uInput; workername = $wInput }
try {
$jsonContent = $Config | ConvertTo-Json -Depth 2
$fullPath = Join-Path (Get-Location) $ConfigFile
[System.IO.File]::WriteAllText($fullPath, $jsonContent)
} catch {
Show-Error "Failed to save configuration file."
exit
}
}
# --- 2. Check Python ---
$pythonExists = $false
try {
$ver = python --version 2>&1
if ($ver -match "Python 3") { $pythonExists = $true }
} catch {}
if (-not $pythonExists) {
[System.Windows.Forms.MessageBox]::Show("Python is missing.`n`nClick OK to install it automatically.`n(This may take 1-2 minutes.)", "Fractum Setup", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
try {
$installer = "$env:TEMP\python_installer.exe"
Invoke-WebRequest "https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe" -OutFile $installer -UseBasicParsing
Start-Process -FilePath $installer -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1 Include_test=0" -Wait
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
} catch {
Show-Error "Failed to install Python."
exit
}
}
# --- 3. Dependencies ---
try { pip install requests --disable-pip-version-check | Out-Null } catch { python -m pip install requests | Out-Null }
# --- 4. Download Worker ---
try {
Invoke-WebRequest $WorkerUrl -OutFile "worker.py" -UseBasicParsing
} catch {
if (-not (Test-Path "worker.py")) {
Show-Error "Could not download worker script.`nCheck internet connection."
exit
}
}
# --- 5. Launch Worker ---
# This opens the worker in a standard console window and closes the launcher.
$CurrentDir = Get-Location
Start-Process python -ArgumentList "worker.py --manager $ManagerUrl --jobs 1" -WorkingDirectory $CurrentDir