eve-watcher/setup.ps1
2026-06-14 07:17:46 +00:00

92 lines
3.9 KiB
PowerShell

<#
setup.ps1 - one-shot installer for the Eve Retriever ore-hold watcher.
Run from an ADMIN PowerShell. Installs Python + Tesseract (via winget),
installs python deps, creates config.ini with a fresh random ntfy topic,
and offers to fire a test alert.
You normally don't call this directly - use the one-liner in the chat /
README, which pulls the repo first and then runs this.
#>
$ErrorActionPreference = "Stop"
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $here
Write-Host "=== Eve ore-hold watcher setup ===" -ForegroundColor Cyan
Write-Host "Working in: $here"
function Refresh-Path {
$m = [Environment]::GetEnvironmentVariable("Path", "Machine")
$u = [Environment]::GetEnvironmentVariable("Path", "User")
$env:Path = "$m;$u"
}
function Have($cmd) { [bool](Get-Command $cmd -ErrorAction SilentlyContinue) }
# --- winget present? ---
if (-not (Have "winget")) {
Write-Warning "winget not found. Install 'App Installer' from the Microsoft Store, then re-run."
exit 1
}
# --- Python ---
if (-not (Have "python")) {
Write-Host "Installing Python 3..." -ForegroundColor Yellow
winget install --id Python.Python.3.12 -e --silent --accept-package-agreements --accept-source-agreements
Refresh-Path
}
if (-not (Have "python")) {
Write-Warning "Python installed but not on PATH yet. Close & reopen PowerShell, then re-run this script."
exit 1
}
Write-Host ("Python: " + (python --version)) -ForegroundColor Green
# --- Tesseract (for OCR mode; harmless if you only use timer mode) ---
$tess = "C:\Program Files\Tesseract-OCR\tesseract.exe"
if (-not (Test-Path $tess) -and -not (Have "tesseract")) {
Write-Host "Installing Tesseract-OCR (for OCR mode)..." -ForegroundColor Yellow
try {
winget install --id UB-Mannheim.TesseractOCR -e --silent --accept-package-agreements --accept-source-agreements
Refresh-Path
} catch {
Write-Warning "Tesseract install skipped/failed - OCR mode won't work until it's installed, but timer mode will."
}
}
if (Have "tesseract") { $tess = (Get-Command tesseract).Source }
# --- python deps ---
Write-Host "Installing python packages..." -ForegroundColor Yellow
python -m pip install --upgrade pip --quiet
python -m pip install -r (Join-Path $here "requirements.txt") --quiet
Write-Host "Packages installed." -ForegroundColor Green
# --- config.ini ---
$cfg = Join-Path $here "config.ini"
if (-not (Test-Path $cfg)) {
Copy-Item (Join-Path $here "config.ini.example") $cfg
# fresh random ntfy topic
$rand = -join ((48..57) + (97..122) | Get-Random -Count 10 | ForEach-Object {[char]$_})
$topic = "eve-retriever-$rand"
(Get-Content $cfg) `
-replace '^topic\s*=.*', "topic = $topic" `
-replace '^tesseract_cmd\s*=.*', "tesseract_cmd = $tess" `
| Set-Content $cfg
Write-Host ""
Write-Host "Created config.ini with ntfy topic:" -ForegroundColor Cyan
Write-Host " $topic" -ForegroundColor White
Write-Host " -> In the ntfy app on your phone: Add subscription -> '$topic'" -ForegroundColor White
} else {
Write-Host "config.ini already exists, leaving it as-is." -ForegroundColor Green
$topic = ((Get-Content $cfg) -match '^topic\s*=' ) -replace '^topic\s*=\s*',''
}
Write-Host ""
Write-Host "=== Done. Next steps ===" -ForegroundColor Cyan
Write-Host "1. Subscribe to topic '$topic' in the ntfy phone app (if you haven't)."
Write-Host "2. Test delivery: python eve_orehold_watcher.py --test"
Write-Host "3a. Timer mode: set [watcher] mode=timer + [timer] yield_m3_per_min, then run it."
Write-Host "3b. OCR mode: python eve_orehold_watcher.py --snip (draw box over the m3 text), then run it."
Write-Host "Run the watcher: python eve_orehold_watcher.py"
Write-Host ""
$ans = Read-Host "Fire a test alert now to confirm phone + toast work? (y/N)"
if ($ans -eq "y") { python (Join-Path $here "eve_orehold_watcher.py") --test }