#Requires -RunAsAdministrator <# .SYNOPSIS JARVIS Agent installer for Windows. .DESCRIPTION Installs JARVIS Agent as a Windows Service that auto-starts at boot. Requires: PowerShell 5.1+, internet access, and Administrator rights. .EXAMPLE # Interactive install (prompts for registration key): irm https://jarvis.orbishosting.com/agent/install-windows.ps1 | iex # Silent install with key: $env:JARVIS_REG_KEY='your_key_here'; irm https://jarvis.orbishosting.com/agent/install-windows.ps1 | iex #> $ErrorActionPreference = 'Stop' $JARVIS_URL = 'https://jarvis.orbishosting.com' $INSTALL_DIR = 'C:\ProgramData\jarvis-agent' $SERVICE_NAME = 'JARVISAgent' $AGENT_SCRIPT = "$INSTALL_DIR\jarvis-agent-windows.py" $CONFIG_FILE = "$INSTALL_DIR\config.json" function Write-Step { param($msg) Write-Host "`n[JARVIS] $msg" -ForegroundColor Cyan } function Write-OK { param($msg) Write-Host " OK: $msg" -ForegroundColor Green } function Write-Fail { param($msg) Write-Host " ERROR: $msg" -ForegroundColor Red; exit 1 } Write-Host "`n========================================" -ForegroundColor Yellow Write-Host " JARVIS Agent Installer for Windows" -ForegroundColor Yellow Write-Host "========================================`n" -ForegroundColor Yellow # ── Stop existing service if running ───────────────────────────────────────── $existing = Get-Service -Name $SERVICE_NAME -ErrorAction SilentlyContinue if ($existing) { Write-Step "Stopping existing JARVIS Agent service..." if ($existing.Status -eq 'Running') { Stop-Service -Name $SERVICE_NAME -Force Start-Sleep 2 } try { & python "$INSTALL_DIR\jarvis-agent-windows.py" remove 2>$null } catch {} Write-OK "Existing service removed." } # ── Check / install Python ──────────────────────────────────────────────────── Write-Step "Checking Python..." $py = Get-Command python -ErrorAction SilentlyContinue if (-not $py) { Write-Host " Python not found. Installing via winget..." -ForegroundColor Yellow if (-not (Get-Command winget -ErrorAction SilentlyContinue)) { Write-Fail "winget not available. Please install Python 3.11+ from https://python.org and re-run." } winget install -e --id Python.Python.3.11 --silent --accept-package-agreements --accept-source-agreements $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User") $py = Get-Command python -ErrorAction SilentlyContinue if (-not $py) { Write-Fail "Python install failed. Please install manually from https://python.org" } } $pyVersion = & python --version 2>&1 Write-OK $pyVersion # ── Install pywin32 ─────────────────────────────────────────────────────────── Write-Step "Checking pywin32..." $checkWin32 = & python -c "import win32service; print('ok')" 2>&1 if ($checkWin32 -ne 'ok') { Write-Host " Installing pywin32..." -ForegroundColor Yellow & python -m pip install --quiet pywin32 & python -m pywin32_postinstall -install 2>$null Write-OK "pywin32 installed." } else { Write-OK "pywin32 already installed." } # ── Create install dir ──────────────────────────────────────────────────────── Write-Step "Creating install directory..." New-Item -ItemType Directory -Path $INSTALL_DIR -Force | Out-Null Write-OK $INSTALL_DIR # ── Download agent script ───────────────────────────────────────────────────── Write-Step "Downloading JARVIS agent..." try { Invoke-WebRequest -Uri "$JARVIS_URL/agent/jarvis-agent-windows.py" -OutFile $AGENT_SCRIPT -UseBasicParsing Write-OK "Agent downloaded to $AGENT_SCRIPT" } catch { Write-Fail "Failed to download agent: $_" } # ── Get registration key ────────────────────────────────────────────────────── $regKey = $env:JARVIS_REG_KEY if (-not $regKey -and (Test-Path $CONFIG_FILE)) { $existingCfg = Get-Content $CONFIG_FILE | ConvertFrom-Json $regKey = $existingCfg.registration_key if ($regKey) { Write-OK "Using existing registration key from config." } } if (-not $regKey) { $regKey = Read-Host "`n Enter JARVIS registration key" if (-not $regKey) { Write-Fail "Registration key required." } } # ── Get hostname ────────────────────────────────────────────────────────────── $hostname = $env:COMPUTERNAME $customHostname = $env:JARVIS_HOSTNAME if ($customHostname) { $hostname = $customHostname } # ── Write config ────────────────────────────────────────────────────────────── Write-Step "Writing config..." $cfg = @{ jarvis_url = $JARVIS_URL registration_key = $regKey hostname = $hostname agent_type = 'windows' ssl_verify = $true poll_interval = 30 heartbeat_every = 10 update_check_hours = 24 watch_services = @('WinDefend', 'Spooler', 'wuauserv') } | ConvertTo-Json -Depth 5 $cfg | Out-File -FilePath $CONFIG_FILE -Encoding utf8 Write-OK "Config written to $CONFIG_FILE" # ── Install Windows Service ─────────────────────────────────────────────────── Write-Step "Installing Windows service..." $pyPath = (Get-Command python).Source & $pyPath "$AGENT_SCRIPT" --startup auto install if ($LASTEXITCODE -ne 0) { Write-Fail "Service install failed." } Write-OK "Service '$SERVICE_NAME' installed." # ── Start service ───────────────────────────────────────────────────────────── Write-Step "Starting service..." Start-Service -Name $SERVICE_NAME Start-Sleep 3 $svc = Get-Service -Name $SERVICE_NAME if ($svc.Status -ne 'Running') { Write-Fail "Service failed to start. Check C:\ProgramData\jarvis-agent\jarvis-agent.log" } Write-OK "Service is running." # ── Test connectivity ───────────────────────────────────────────────────────── Write-Step "Testing JARVIS connection..." try { $ping = Invoke-RestMethod -Uri "$JARVIS_URL/api/ping" -TimeoutSec 10 Write-OK "JARVIS is online: $($ping.codename)" } catch { Write-Host " WARNING: Could not reach JARVIS at $JARVIS_URL - check connectivity." -ForegroundColor Yellow } Write-Host "`n========================================" -ForegroundColor Green Write-Host " JARVIS Agent installed successfully!" -ForegroundColor Green Write-Host " Hostname: $hostname" -ForegroundColor Green Write-Host " Service: $SERVICE_NAME (auto-start at boot)" -ForegroundColor Green Write-Host " Logs: C:\ProgramData\jarvis-agent\jarvis-agent.log" -ForegroundColor Green Write-Host "========================================`n" -ForegroundColor Green