mirror of
https://github.com/myronblair/jarvis
synced 2026-07-28 00:34:35 -05:00
131 lines
6.5 KiB
PowerShell
131 lines
6.5 KiB
PowerShell
#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.
|
|
No Python installation needed — this installs the standalone .exe build.
|
|
|
|
.EXAMPLE
|
|
# Interactive install (prompts for registration key):
|
|
irm https://jarvis.orbishosting.com:1972/agent/install-windows.ps1 | iex
|
|
|
|
# Silent install with key:
|
|
$env:JARVIS_REG_KEY='your_key_here'; irm https://jarvis.orbishosting.com:1972/agent/install-windows.ps1 | iex
|
|
#>
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
# Fixed 2026-07-07: jarvis.orbishosting.com on the default port (80/443) is not
|
|
# reachable from outside the LAN at all (no FortiGate VIP forwards it) — every
|
|
# external install using the old default URL would have failed outright. Port
|
|
# 1972 is the confirmed-working external path (same fix applied to the GitHub
|
|
# webhook the same day).
|
|
$JARVIS_URL = 'http://jarvis.orbishosting.com:1972'
|
|
$INSTALL_DIR = 'C:\ProgramData\jarvis-agent'
|
|
$SERVICE_NAME = 'JARVISAgent'
|
|
$AGENT_EXE = "$INSTALL_DIR\jarvis-agent-windows.exe"
|
|
$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 {
|
|
if (Test-Path $AGENT_EXE) { & $AGENT_EXE remove 2>$null }
|
|
} catch {}
|
|
Write-OK "Existing service removed."
|
|
}
|
|
|
|
# ── Create install dir ────────────────────────────────────────────────────────
|
|
Write-Step "Creating install directory..."
|
|
New-Item -ItemType Directory -Path $INSTALL_DIR -Force | Out-Null
|
|
Write-OK $INSTALL_DIR
|
|
|
|
# ── Download agent exe ─────────────────────────────────────────────────────────
|
|
# No Python/pywin32 dependency anymore — this is a self-contained PyInstaller
|
|
# build with everything it needs bundled in.
|
|
Write-Step "Downloading JARVIS agent..."
|
|
try {
|
|
Invoke-WebRequest -Uri "$JARVIS_URL/agent/jarvis-agent-windows.exe" -OutFile $AGENT_EXE -UseBasicParsing
|
|
Write-OK "Agent downloaded to $AGENT_EXE"
|
|
} 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..."
|
|
& $AGENT_EXE --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
|