mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 12:42:38 +00:00
3a898b5071
- Loader 1.3 downloads into a protected run folder of its own (%ProgramData%\AutopilotMonitor-Loader-<8 hex>), runs the installer only when it is signed by the pinned publisher and declares the installer role and version 2.7 or later, removes the folder after a successful run and never touches the agent folder. Unbound arguments now reach the installer by name; the array splat bound them by position. - Installer 2.7 refuses without elevation and decides before it writes: guards read HKLM through the 64-bit view (a 32-bit host never saw the deployment marker), guard 5 is covered by the agent check. An agent's folder stays as it is, a skip without agent removes the folder, an install starts from an emptied, protected folder and stages the ZIP in a run folder. It moves the MSI's working directory out, writes stderr only on failure and removes the copy older loaders left at the fixed path. - Help texts of both scripts state what customers need; .CHANGELOG, which made Get-Help ignore the help, gives way to the Platform Changelog. - OOBE go-script: the installer's shared helpers, its own elevation check (#Requires is ignored under irm | iex), a run folder. - Publish: version read line-anchored, the loader's own check on the exact publish bytes, installers before loaders, -Channel dev (dispatch input). - Bootstrap MSI 1.2.0; Test-ShouldBootstrapAgent reads the 64-bit view; Uninstall removes loader run folders and keeps the Deployed marker. - Tests: Pester unit suites, an integration harness running the real scripts (loader 1.2 and the MSI 1.0 runner frozen in TestData), BootstrapContractTests; the gate runs on windows-2022 and windows-2025, once more as SYSTEM, and against a real standard user. [skip actions]: published by a dispatch of publish-scripts.yml, channel dev first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
2.3 KiB
PowerShell
56 lines
2.3 KiB
PowerShell
# Invoke-BootstrapDownload.ps1 - thin runner embedded in the Bootstrap MSI.
|
|
#
|
|
# The MSI is only a delivery vehicle (MDM LOB channel installs earlier than the IME
|
|
# script/app batches during Autopilot Device Preparation). This runner downloads the
|
|
# CURRENT Install-AutopilotMonitor.ps1 from the download endpoint and executes it, so
|
|
# every piece of real bootstrap logic (guards, relax rules, agent download) stays
|
|
# server-updatable without re-shipping the MSI.
|
|
#
|
|
# Fail-soft by design: the runner always exits 0 so a transient network failure never
|
|
# marks the LOB install as failed; diagnostics go to bootstrap-msi.log.
|
|
# ASCII only - no special characters in this file.
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$baseDir = Join-Path $env:ProgramData 'AutopilotMonitor'
|
|
$logDir = Join-Path $baseDir 'Logs'
|
|
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
|
|
$log = Join-Path $logDir 'bootstrap-msi.log'
|
|
|
|
function Write-Log([string]$message) {
|
|
Add-Content -Path $log -Value ("[{0}] {1}" -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $message)
|
|
}
|
|
|
|
try {
|
|
Write-Log "MSI bootstrap runner started (user=$env:USERNAME, pid=$PID)."
|
|
|
|
if (Test-Path 'HKLM:\SOFTWARE\AutopilotMonitor\Deployed') {
|
|
Write-Log 'Deployed marker present - skipping, another channel already installed the agent.'
|
|
exit 0
|
|
}
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
$url = 'https://download.autopilotmonitor.com/agent/Install-AutopilotMonitor.ps1'
|
|
$dest = Join-Path $baseDir 'Install-AutopilotMonitor.ps1'
|
|
|
|
for ($attempt = 1; $attempt -le 3; $attempt++) {
|
|
try {
|
|
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $dest
|
|
break
|
|
} catch {
|
|
Write-Log "Download attempt $attempt failed: $_"
|
|
if ($attempt -eq 3) { throw }
|
|
Start-Sleep -Seconds 10
|
|
}
|
|
}
|
|
|
|
Write-Log "Bootstrap script downloaded to $dest - executing."
|
|
# PS 5.1 file redirection (*>>) writes UTF-16LE, which garbles a log otherwise
|
|
# written via Add-Content (ANSI). Route through Add-Content for one encoding.
|
|
& $dest *>&1 | ForEach-Object { $_.ToString() } | Add-Content -Path $log
|
|
Write-Log "Bootstrap script finished (exit code $LASTEXITCODE)."
|
|
exit 0
|
|
} catch {
|
|
Write-Log ("MSI bootstrap runner failed: " + ($_ | Out-String))
|
|
exit 0
|
|
}
|