# install.ps1 — install telemetry_monitor as a Windows Scheduled Task # # Run from the directory containing this script (PowerShell 5+): # powershell -ExecutionPolicy Bypass -File install.ps1 # # Requires: user with Task Scheduler access (standard user is sufficient) param ( [switch]$Uninstall, [string]$Email = "" ) $ErrorActionPreference = "Stop" $IngestUrl = "https://aiyoo.in:4443/jeeves/ingest" $IngestToken = if ($env:INGEST_TOKEN) { $env:INGEST_TOKEN } else { "secret-token" } $TaskName = "telemetry_monitor" $InstallDir = "$env:ProgramFiles\telemetry_monitor" $BinaryName = "telemetry_monitor.exe" $BinaryDst = Join-Path $InstallDir $BinaryName if ($Uninstall) { Write-Host "Uninstalling $TaskName..." if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) { Stop-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false } if (Get-ScheduledTask -TaskName "sysmonitor" -ErrorAction SilentlyContinue) { Stop-ScheduledTask -TaskName "sysmonitor" -ErrorAction SilentlyContinue Unregister-ScheduledTask -TaskName "sysmonitor" -Confirm:$false } if (Test-Path $InstallDir) { Remove-Item -Recurse -Force $InstallDir -ErrorAction SilentlyContinue } Write-Host "✓ $TaskName service and files successfully removed." exit 0 } # Prompt interactively if email not provided and console is interactive if ([string]::IsNullOrWhiteSpace($Email) -and [Environment]::UserInteractive -and -not [Console]::IsInputRedirected) { Write-Host "── Device Owner Configuration ─────────────────────────────────────────" Write-Host "Enter primary user/owner email for this device" $Prompted = Read-Host "(or press Enter to auto-detect via Active Directory/UPN)" if (-not [string]::IsNullOrWhiteSpace($Prompted)) { if ($Prompted.Length -le 254 -and $Prompted -match "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$") { $Email = $Prompted.Trim() Write-Host "✓ Registered initial owner: $Email" } else { Write-Host "⚠ Invalid email format; continuing with automatic directory resolution." } } else { Write-Host "Continuing with automatic directory resolution." } Write-Host "────────────────────────────────────────────────────────────────────────" } $BinarySrc = Join-Path $PSScriptRoot "telemetry_monitor-windows-amd64.exe" if (-not (Test-Path $BinarySrc)) { $BinarySrc = Join-Path $PSScriptRoot "dist\telemetry_monitor-windows-amd64.exe" } if (-not (Test-Path $BinarySrc)) { Write-Error "Binary not found: $BinarySrc" exit 1 } Write-Host "Installing telemetry_monitor (Windows / Scheduled Task)..." # Copy binary New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null Copy-Item -Force $BinarySrc $BinaryDst Write-Host " binary -> $BinaryDst" # Remove existing task if present if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) { Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false } # Also remove legacy task if present if (Get-ScheduledTask -TaskName "sysmonitor" -ErrorAction SilentlyContinue) { Unregister-ScheduledTask -TaskName "sysmonitor" -Confirm:$false } $TaskArgs = "-ingest $IngestUrl -no-local-storage" if ($IngestToken -ne "") { $TaskArgs += " -ingest-token $IngestToken" } if (-not [string]::IsNullOrWhiteSpace($Email)) { $TaskArgs += " -email `"$Email`"" } # Register new task $Action = New-ScheduledTaskAction ` -Execute $BinaryDst ` -Argument $TaskArgs $Trigger = New-ScheduledTaskTrigger -AtStartup $Settings = New-ScheduledTaskSettingsSet ` -ExecutionTimeLimit ([TimeSpan]::Zero) ` -RestartCount 3 ` -RestartInterval (New-TimeSpan -Minutes 1) Register-ScheduledTask ` -TaskName $TaskName ` -Action $Action ` -Trigger $Trigger ` -Settings $Settings ` -RunLevel Highest ` -Force | Out-Null Write-Host " task -> Task Scheduler\$TaskName (triggers at startup)" # Start immediately Start-ScheduledTask -TaskName $TaskName Write-Host "" Write-Host "telemetry_monitor started. Sending to: $IngestUrl" Write-Host "Check status: Get-ScheduledTask -TaskName telemetry_monitor"