sheep overhaul

This commit is contained in:
Nathan
2025-11-05 16:19:24 -07:00
parent 37bdfcb862
commit 07a413e23f
2 changed files with 1048 additions and 62 deletions

View File

@@ -6,92 +6,120 @@ function Show-Header {
Write-Host
}
$defaultSheepItPath = "C:\Users\Nathan\Desktop\sheepit-autoupdate.exe"
$SheepItJarUrl = 'https://www.sheepit-renderfarm.com/media/applet/client-latest.jar'
$script:SheepItUsername = $null
$script:SheepItRenderKey = $null
function Initialize-SheepItCredentials {
if (-not $script:SheepItUsername) {
$script:SheepItUsername = "RaincloudTheDragon"
}
if (-not $script:SheepItRenderKey) {
$script:SheepItRenderKey = "IfCOWBHFQpceG0601DmyrwOOJOAp2UJAQ0O0X0jF"
}
}
$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 }
@{ ID = 1; Name = "i9kf"; SSHArgs = "-t i9kf"; Enabled = $true },
@{ ID = 2; Name = "blender-boss"; SSHArgs = "-t blender-boss"; Enabled = $true },
@{ ID = 3; Name = "max"; SSHArgs = "-t max"; Enabled = $true },
@{ ID = 4; Name = "masterbox"; SSHArgs = "-t masterbox"; Enabled = $true },
@{ ID = 5; Name = "echo"; SSHArgs = "-t echo"; Enabled = $true },
@{ ID = 6; Name = "i9-13ks"; SSHArgs = "-t -p 22146 i9-13ks"; Enabled = $true }
)
function Get-RemoteSheepItCommand {
param([string]$ExecutablePath)
param(
[string]$RenderKey,
[string]$Username
)
$safeKey = $RenderKey -replace "'", "''"
$safeUser = $Username -replace "'", "''"
$userLine = if ([string]::IsNullOrWhiteSpace($Username)) {
''
} else {
" Write-Host 'Authenticating as ${safeUser} via render key.' -ForegroundColor Yellow`n"
}
@"
`$exe = "$ExecutablePath"
if (-not (Test-Path `$exe)) {
Write-Host "SheepIt launcher not found at `$exe" -ForegroundColor Red
exit 1
}
`$ErrorActionPreference = 'Stop'
`$dir = Split-Path `$exe
Write-Host "Launching SheepIt at `$exe" -ForegroundColor Cyan
`$proc = Start-Process -FilePath `$exe -WorkingDirectory `$dir -WindowStyle Minimized -PassThru
if (`$proc) {
`$id = `$proc.Id
Write-Host ("SheepIt launcher started (PID: {0})." -f `$id) -ForegroundColor Green
Start-Sleep -Seconds 1
try {
`$appData = [Environment]::GetFolderPath('ApplicationData')
`$sheepDir = Join-Path `$appData 'sheepit'
if (-not (Test-Path `$sheepDir)) {
New-Item -Path `$sheepDir -ItemType Directory -Force | Out-Null
}
if (Get-Process -Id `$id -ErrorAction SilentlyContinue) {
Write-Host ("SheepIt launcher is still running (PID: {0})." -f `$id) -ForegroundColor Green
}
else {
try {
`$children = Get-CimInstance Win32_Process -Filter "ParentProcessId=`$id"
if (`$children) {
Write-Host "Launcher handed off to:" -ForegroundColor Green
foreach (`$child in `$children) {
Write-Host (" {0} (PID: {1})" -f `$child.Name, `$child.ProcessId) -ForegroundColor Green
}
}
else {
Write-Host "Launcher exited immediately after starting. Check Task Manager for SheepIt/Java processes." -ForegroundColor Yellow
}
}
catch {
Write-Host "Unable to inspect child processes." -ForegroundColor Yellow
}
}
`$jarPath = Join-Path `$sheepDir 'sheepit-client.jar'
Write-Host "Downloading SheepIt client..." -ForegroundColor Cyan
Invoke-WebRequest -Uri '$SheepItJarUrl' -OutFile `$jarPath -UseBasicParsing
Write-Host "Download complete." -ForegroundColor Green
Write-Host "Starting SheepIt client..." -ForegroundColor Cyan
${userLine} Set-Location `$sheepDir
& java -jar `$jarPath --ui text --stdout --verbose -gpu optix 0 --renderkey '${safeKey}'
}
else {
Write-Host "SheepIt start confirmed." -ForegroundColor Green
catch {
Write-Host "Error: `$($_.Exception.Message)" -ForegroundColor Red
}
exit 0
"@
}
function New-SheepItSessionScript {
param(
[object]$Worker,
[string]$EncodedCommand
)
@"
Write-Host 'Connecting to $($Worker.Name)...' -ForegroundColor Cyan
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=30 $($Worker.SSHArgs) `"powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -EncodedCommand $EncodedCommand`"
Write-Host "`nSSH session ended." -ForegroundColor Yellow
Read-Host "Press Enter to close"
"@
}
function Start-SheepItTab {
param(
[string]$Title,
[string]$Content
)
$tempScript = [System.IO.Path]::GetTempFileName() + '.ps1'
Set-Content -Path $tempScript -Value $Content -Encoding UTF8
if (Get-Command wt.exe -ErrorAction SilentlyContinue) {
Start-Process wt.exe -ArgumentList "-w 0 new-tab --title `"$Title`" powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -File `"$tempScript`""
} else {
Start-Process powershell -ArgumentList "-NoLogo -NoProfile -ExecutionPolicy Bypass -File `"$tempScript`""
}
}
function Start-SheepItWorker {
param([object]$Worker)
if (-not $Worker.Enabled) {
Write-Host "$($Worker.Name) does not have SheepIt configured yet." -ForegroundColor Yellow
Write-Host "$($Worker.Name) is not enabled for SheepIt." -ForegroundColor Yellow
return
}
$remoteCommand = Get-RemoteSheepItCommand -ExecutablePath $Worker.SheepItPath
Initialize-SheepItCredentials
$remoteCommand = Get-RemoteSheepItCommand -RenderKey $script:SheepItRenderKey -Username $script:SheepItUsername
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($remoteCommand))
$ssh = "ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=30 $($Worker.SSHArgs) `"powershell -NoLogo -NoProfile -EncodedCommand $encoded`""
$sessionScript = New-SheepItSessionScript -Worker $Worker -EncodedCommand $encoded
$title = "$($Worker.Name) - SheepIt"
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
}
Start-SheepItTab -Title $title -Content $sessionScript
Write-Host "Opened SheepIt session for $($Worker.Name) in a new terminal tab." -ForegroundColor Green
}
function Start-AllSheepIt {
Initialize-SheepItCredentials
$targets = $workers | Where-Object { $_.Enabled }
if (-not $targets) {
@@ -101,7 +129,7 @@ function Start-AllSheepIt {
foreach ($worker in $targets) {
Start-SheepItWorker -Worker $worker
Start-Sleep -Seconds 1
Start-Sleep -Milliseconds 200
}
}
@@ -111,7 +139,7 @@ function Select-SheepItWorker {
Write-Host "Select a system:" -ForegroundColor Magenta
foreach ($worker in $workers) {
$status = if ($worker.Enabled) { "ready" } else { "missing exe" }
$status = if ($worker.Enabled) { "ready" } else { "disabled" }
$color = if ($worker.Enabled) { "Green" } else { "DarkYellow" }
Write-Host ("{0}. {1} ({2})" -f $worker.ID, $worker.Name, $status) -ForegroundColor $color
}
@@ -144,6 +172,8 @@ function Select-SheepItWorker {
}
}
Initialize-SheepItCredentials
while ($true) {
Show-Header
Write-Host "Main Menu:" -ForegroundColor Magenta