145 lines
4.8 KiB
PowerShell
145 lines
4.8 KiB
PowerShell
|
|
function Show-Header {
|
||
|
|
Clear-Host
|
||
|
|
Write-Host "====================================" -ForegroundColor Cyan
|
||
|
|
Write-Host " UNIFIED SHEEPIT LAUNCHER" -ForegroundColor Cyan
|
||
|
|
Write-Host "====================================" -ForegroundColor Cyan
|
||
|
|
Write-Host
|
||
|
|
}
|
||
|
|
|
||
|
|
$defaultSheepItPath = "C:\Users\Nathan\Desktop\sheepit-autoupdate.exe"
|
||
|
|
|
||
|
|
$workers = @(
|
||
|
|
@{ ID = 1; Name = "i9kf"; SSHArgs = "-t i9kf"; SheepItPath = $defaultSheepItPath; Enabled = $false },
|
||
|
|
@{ ID = 2; Name = "blender-boss"; SSHArgs = "-t blender-boss"; SheepItPath = $defaultSheepItPath; Enabled = $true },
|
||
|
|
@{ ID = 3; Name = "max"; SSHArgs = "-t max"; SheepItPath = $defaultSheepItPath; Enabled = $true },
|
||
|
|
@{ ID = 4; Name = "masterbox"; SSHArgs = "-t masterbox"; SheepItPath = $defaultSheepItPath; Enabled = $true },
|
||
|
|
@{ ID = 5; Name = "echo"; SSHArgs = "-t echo"; SheepItPath = $defaultSheepItPath; Enabled = $true },
|
||
|
|
@{ ID = 6; Name = "i9-13ks"; SSHArgs = "-t -p 22146 i9-13ks"; SheepItPath = $defaultSheepItPath; Enabled = $true }
|
||
|
|
)
|
||
|
|
|
||
|
|
function Get-RemoteSheepItCommand {
|
||
|
|
param([string]$ExecutablePath)
|
||
|
|
|
||
|
|
@"
|
||
|
|
`$exe = "$ExecutablePath"
|
||
|
|
if (-not (Test-Path `$exe)) {
|
||
|
|
Write-Host "SheepIt launcher not found at `$exe" -ForegroundColor Red
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
`$dir = Split-Path `$exe
|
||
|
|
Write-Host "Launching SheepIt at `$exe" -ForegroundColor Cyan
|
||
|
|
`$proc = Start-Process -FilePath `$exe -WorkingDirectory `$dir -WindowStyle Minimized -PassThru
|
||
|
|
Write-Host "SheepIt started (PID: `$($proc.Id))." -ForegroundColor Green
|
||
|
|
exit 0
|
||
|
|
"@
|
||
|
|
}
|
||
|
|
|
||
|
|
function Start-SheepItWorker {
|
||
|
|
param([object]$Worker)
|
||
|
|
|
||
|
|
if (-not $Worker.Enabled) {
|
||
|
|
Write-Host "$($Worker.Name) does not have SheepIt configured yet." -ForegroundColor Yellow
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
$remoteCommand = Get-RemoteSheepItCommand -ExecutablePath $Worker.SheepItPath
|
||
|
|
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($remoteCommand))
|
||
|
|
$ssh = "ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=30 $($Worker.SSHArgs) `"powershell -NoLogo -NoProfile -EncodedCommand $encoded`""
|
||
|
|
|
||
|
|
Write-Host "Connecting to $($Worker.Name)..." -ForegroundColor Cyan
|
||
|
|
try {
|
||
|
|
Invoke-Expression $ssh
|
||
|
|
$exitCode = $LASTEXITCODE
|
||
|
|
|
||
|
|
if ($exitCode -eq 0) {
|
||
|
|
Write-Host "SheepIt launched on $($Worker.Name)." -ForegroundColor Green
|
||
|
|
} else {
|
||
|
|
Write-Host "Launch on $($Worker.Name) exited with $exitCode." -ForegroundColor Red
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch {
|
||
|
|
Write-Host "Connection to $($Worker.Name) failed: $($_.Exception.Message)" -ForegroundColor Red
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function Start-AllSheepIt {
|
||
|
|
$targets = $workers | Where-Object { $_.Enabled }
|
||
|
|
|
||
|
|
if (-not $targets) {
|
||
|
|
Write-Host "No systems are ready for SheepIt." -ForegroundColor Yellow
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($worker in $targets) {
|
||
|
|
Start-SheepItWorker -Worker $worker
|
||
|
|
Start-Sleep -Seconds 1
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function Select-SheepItWorker {
|
||
|
|
while ($true) {
|
||
|
|
Show-Header
|
||
|
|
Write-Host "Select a system:" -ForegroundColor Magenta
|
||
|
|
|
||
|
|
foreach ($worker in $workers) {
|
||
|
|
$status = if ($worker.Enabled) { "ready" } else { "missing exe" }
|
||
|
|
$color = if ($worker.Enabled) { "Green" } else { "DarkYellow" }
|
||
|
|
Write-Host ("{0}. {1} ({2})" -f $worker.ID, $worker.Name, $status) -ForegroundColor $color
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Host "B. Back" -ForegroundColor Yellow
|
||
|
|
$selection = Read-Host "Choose system"
|
||
|
|
|
||
|
|
if ($selection -match '^[Bb]$') {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($selection -match '^\d+$') {
|
||
|
|
$id = [int]$selection
|
||
|
|
$worker = $workers | Where-Object { $_.ID -eq $id }
|
||
|
|
|
||
|
|
if ($worker) {
|
||
|
|
Start-SheepItWorker -Worker $worker
|
||
|
|
Write-Host
|
||
|
|
Read-Host "Press Enter to return to the main menu" | Out-Null
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Host "Unknown selection." -ForegroundColor Red
|
||
|
|
Start-Sleep -Seconds 1
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
Write-Host "Invalid input." -ForegroundColor Red
|
||
|
|
Start-Sleep -Seconds 1
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
while ($true) {
|
||
|
|
Show-Header
|
||
|
|
Write-Host "Main Menu:" -ForegroundColor Magenta
|
||
|
|
Write-Host "1. Launch SheepIt on a single system" -ForegroundColor Yellow
|
||
|
|
Write-Host "2. Launch SheepIt on all ready systems" -ForegroundColor Yellow
|
||
|
|
Write-Host "3. Exit" -ForegroundColor Yellow
|
||
|
|
|
||
|
|
$choice = Read-Host "Select option (1-3)"
|
||
|
|
|
||
|
|
switch ($choice) {
|
||
|
|
'1' { Select-SheepItWorker }
|
||
|
|
'2' {
|
||
|
|
Start-AllSheepIt
|
||
|
|
Write-Host
|
||
|
|
Read-Host "Press Enter to return to the main menu" | Out-Null
|
||
|
|
}
|
||
|
|
'3' { break }
|
||
|
|
default {
|
||
|
|
Write-Host "Invalid selection." -ForegroundColor Red
|
||
|
|
Start-Sleep -Seconds 1
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Host "`nExiting SheepIt launcher." -ForegroundColor Cyan
|
||
|
|
|