117 lines
6.5 KiB
PowerShell
117 lines
6.5 KiB
PowerShell
# Sets up The Kurgan:
|
|
# 1. installs the Python packages it needs (into the project's .venv if there is one)
|
|
# 2. installs PawnIO (signed driver used by LibreHardwareMonitor) for CPU sensors, top fans and RAM lighting
|
|
# 3. replaces the old "TT LCD Dashboard" startup task with "The Kurgan" (hidden, admin rights, at logon)
|
|
# 4. with -RetireAIServices: stops and disables the "Strata Local Service" and "Qwen4 Local Service"
|
|
# tasks, so The Kurgan runs whichever LLM server you select (re-enable them with uninstall.ps1)
|
|
# 5. starts The Kurgan; the web UI is at http://127.0.0.1:8080/
|
|
#
|
|
# Run from a normal PowerShell window:
|
|
# powershell -ExecutionPolicy Bypass -File .\setup.ps1 [-RetireAIServices]
|
|
# It asks for administrator rights (UAC) itself.
|
|
|
|
param([switch]$Elevated, [string]$PythonW, [switch]$RetireAIServices)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$TaskName = 'The Kurgan'
|
|
$LegacyTaskName = 'TT LCD Dashboard'
|
|
$AITasks = 'Strata Local Service', 'Qwen4 Local Service'
|
|
$Here = $PSScriptRoot
|
|
|
|
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
|
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
|
|
if (-not $isAdmin) {
|
|
# Prefer the project's own .venv; otherwise use whichever python is on PATH.
|
|
$venvPython = Join-Path $Here '.venv\Scripts\python.exe'
|
|
if (Test-Path $venvPython) {
|
|
$python = $venvPython
|
|
} else {
|
|
$python = (Get-Command python -ErrorAction Stop).Source
|
|
}
|
|
$inVenv = (& $python -c "import sys; print(int(sys.prefix != sys.base_prefix))") -eq '1'
|
|
$pipArgs = if ($inVenv) { @() } else { @('--user') }
|
|
$pythonw = Join-Path (Split-Path $python) 'pythonw.exe'
|
|
if (-not (Test-Path $pythonw)) { throw "pythonw.exe not found next to $python" }
|
|
|
|
Write-Host "Installing Python packages into $(Split-Path (Split-Path $python))..." -ForegroundColor Cyan
|
|
& $python -m pip install @pipArgs --quiet --disable-pip-version-check -r (Join-Path $Here 'requirements.txt')
|
|
if ($LASTEXITCODE -ne 0) { throw "pip install failed" }
|
|
|
|
Write-Host "Requesting administrator rights for PawnIO and the startup task..." -ForegroundColor Cyan
|
|
$argList = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Elevated -PythonW `"$pythonw`""
|
|
if ($RetireAIServices) { $argList += ' -RetireAIServices' }
|
|
$p = Start-Process powershell -Verb RunAs -ArgumentList $argList -Wait -PassThru
|
|
exit $p.ExitCode
|
|
}
|
|
|
|
function Stop-Matching([scriptblock]$Filter) {
|
|
Get-CimInstance Win32_Process | Where-Object $Filter |
|
|
ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
|
|
}
|
|
|
|
try {
|
|
if (-not $PythonW) {
|
|
$venvPythonW = Join-Path $Here '.venv\Scripts\pythonw.exe'
|
|
$PythonW = if (Test-Path $venvPythonW) { $venvPythonW } else {
|
|
Join-Path (Split-Path (Get-Command python -ErrorAction Stop).Source) 'pythonw.exe' }
|
|
}
|
|
|
|
# --- PawnIO -------------------------------------------------------------------------
|
|
$pawn = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PawnIO' -ErrorAction SilentlyContinue
|
|
if ($pawn) {
|
|
Write-Host "PawnIO $($pawn.DisplayVersion) already installed." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Installing PawnIO via winget..." -ForegroundColor Cyan
|
|
winget install --id namazso.PawnIO --exact --silent --accept-source-agreements --accept-package-agreements
|
|
if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne 3010) { throw "winget install of PawnIO failed ($LASTEXITCODE)" }
|
|
}
|
|
|
|
# --- stop any copy that is already running (an LLM server it started ends with it) -----
|
|
foreach ($name in $TaskName, $LegacyTaskName) { Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue }
|
|
Stop-Matching { $_.Name -like 'python*.exe' -and ($_.CommandLine -like '*lcd_dashboard.py*' -or
|
|
$_.CommandLine -like '*-m kurgan*') }
|
|
Unregister-ScheduledTask -TaskName $LegacyTaskName -Confirm:$false -ErrorAction SilentlyContinue
|
|
|
|
# --- the LLM servers' own startup tasks ------------------------------------------------
|
|
if ($RetireAIServices) {
|
|
foreach ($name in $AITasks) {
|
|
if (Get-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue) {
|
|
Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue
|
|
Disable-ScheduledTask -TaskName $name | Out-Null
|
|
Write-Host "Disabled '$name'." -ForegroundColor Green
|
|
}
|
|
}
|
|
# Their trays, and the llama.cpp server the Qwen4 service started.
|
|
Stop-Matching { $_.CommandLine -like '*local-service-tray.py*' -or $_.CommandLine -like '*qwen4-service.pyw*' -or
|
|
($_.Name -eq 'llama-server.exe' -and $_.CommandLine -like '*qwen4-35b-a3b\service\presets.ini*') }
|
|
}
|
|
|
|
# --- scheduled task ------------------------------------------------------------------
|
|
$user = [Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
$action = New-ScheduledTaskAction -Execute $PythonW -Argument '-m kurgan' -WorkingDirectory $Here
|
|
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $user
|
|
$principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Highest
|
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
|
|
-ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 5 -RestartInterval (New-TimeSpan -Minutes 1) `
|
|
-MultipleInstances IgnoreNew -StartWhenAvailable
|
|
Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Principal $principal `
|
|
-Settings $settings -Description 'The Kurgan: LCD dashboard, fans, lighting and the local LLM server' `
|
|
-Force | Out-Null
|
|
Start-ScheduledTask -TaskName $TaskName
|
|
Write-Host "Done. '$TaskName' is running and will start at every logon." -ForegroundColor Green
|
|
Write-Host "Web UI: http://127.0.0.1:8080/ Log: $env:LOCALAPPDATA\Kurgan\kurgan.log"
|
|
if (-not $RetireAIServices) {
|
|
$running = $AITasks | Where-Object { (Get-ScheduledTask -TaskName $_ -ErrorAction SilentlyContinue).State -eq 'Running' }
|
|
if ($running) {
|
|
Write-Host "Still running on their own: $($running -join ', '). The Kurgan only watches them;" -ForegroundColor Yellow
|
|
Write-Host "run setup.ps1 -RetireAIServices to let The Kurgan run and swap them." -ForegroundColor Yellow
|
|
}
|
|
}
|
|
} catch {
|
|
Write-Host "Setup failed: $_" -ForegroundColor Red
|
|
Read-Host "Press Enter to close"
|
|
exit 1
|
|
}
|
|
Start-Sleep -Seconds 4
|