# AgentDo (ad9.io) Windows Installer Script - Pure ASCII (No UTF-8 BOM) # Usage: irm https://ad9.io/win | iex # Override for local E2E: $env:AD9_BASE_URL = "http://127.0.0.1:8080"; irm "$env:AD9_BASE_URL/win" | iex $ErrorActionPreference = "Stop" try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } $BaseUrl = if ($env:AD9_BASE_URL -and $env:AD9_BASE_URL.Trim().Length -gt 0) { $env:AD9_BASE_URL.TrimEnd("/") } else { "https://ad9.io" } $InstallRoot = Join-Path $env:LOCALAPPDATA "AD9" $AppDir = Join-Path $InstallRoot "app" $AppExe = Join-Path $AppDir "AgentDo.exe" $TempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("ad9-install-" + [Guid]::NewGuid().ToString("N")) New-Item -ItemType Directory -Force -Path $TempDir | Out-Null New-Item -ItemType Directory -Force -Path $AppDir | Out-Null Write-Host "[AgentDo] Base URL: $BaseUrl" -ForegroundColor Cyan $ManifestUrl = "$BaseUrl/download/windows/manifest.json" $PortalFallbackUrl = "https://ad9.io/download/windows" $PrimaryPortalUrl = "$BaseUrl/download/windows" $ExpectedSha256 = $null $GithubReleaseUrl = $null $ManifestDownloadUrl = $null Write-Host "[AgentDo] Fetching release manifest from $ManifestUrl ..." try { $Manifest = Invoke-RestMethod -Uri $ManifestUrl -UseBasicParsing -TimeoutSec 30 if ($Manifest.sha256) { $ExpectedSha256 = ($Manifest.sha256.ToString().Trim().ToLowerInvariant()) } if ($Manifest.github_release_url) { $GhCand = $Manifest.github_release_url.ToString().Trim() if ($GhCand -match "^https?://") { $GithubReleaseUrl = $GhCand } } if ($Manifest.download_url) { $DlCand = $Manifest.download_url.ToString().Trim() if ($DlCand -match "^https?://") { $ManifestDownloadUrl = $DlCand } elseif ($DlCand.Length -gt 0) { $ManifestDownloadUrl = $BaseUrl + $DlCand } } } catch { Write-Host "[AgentDo] Manifest lookup failed; falling back directly to portal download..." -ForegroundColor Yellow } $CandidateUrls = New-Object System.Collections.Generic.List[string] if ($GithubReleaseUrl) { $CandidateUrls.Add($GithubReleaseUrl) } if ($ManifestDownloadUrl -and (-not $CandidateUrls.Contains($ManifestDownloadUrl))) { $CandidateUrls.Add($ManifestDownloadUrl) } if (-not $CandidateUrls.Contains($PrimaryPortalUrl)) { $CandidateUrls.Add($PrimaryPortalUrl) } if (-not $CandidateUrls.Contains($PortalFallbackUrl)) { $CandidateUrls.Add($PortalFallbackUrl) } $InstallerPath = Join-Path $TempDir "AgentDo-Setup.exe" $Downloaded = $false $LastError = $null foreach ($Url in $CandidateUrls) { Write-Host "[AgentDo] Downloading installer from $Url ..." try { Invoke-WebRequest -Uri $Url -OutFile $InstallerPath -UseBasicParsing -TimeoutSec 120 if ((Test-Path $InstallerPath) -and ((Get-Item $InstallerPath).Length -gt 0)) { $Downloaded = $true Write-Host "[AgentDo] Download succeeded from $Url" -ForegroundColor Green break } } catch { $LastError = $_.Exception.Message Write-Host "[AgentDo] Download failed from $Url ($LastError); trying next mirror..." -ForegroundColor Yellow } } if (-not $Downloaded) { Remove-Item -Recurse -Force $TempDir -ErrorAction SilentlyContinue throw "Failed to download AgentDo installer from all configured sources. Last error: $LastError" } $ActualSha256 = (Get-FileHash -Path $InstallerPath -Algorithm SHA256).Hash.ToLowerInvariant() Write-Host "[AgentDo] Downloaded SHA-256: $ActualSha256" if ($ExpectedSha256 -and $ExpectedSha256.Length -eq 64) { if ($ActualSha256 -ne $ExpectedSha256) { Remove-Item -Recurse -Force $TempDir -ErrorAction SilentlyContinue throw "SHA-256 verification failed! Expected $ExpectedSha256 but got $ActualSha256" } Write-Host "[AgentDo] SHA-256 checksum verified." -ForegroundColor Green } else { Write-Host "[AgentDo] SHA-256 computed via Get-FileHash (no manifest pin present)." -ForegroundColor Yellow } Write-Host "[AgentDo] Running silent install to $AppDir ..." $Proc = Start-Process -FilePath $InstallerPath -ArgumentList @("/S", "/D=$AppDir") -Wait -PassThru if ($Proc.ExitCode -ne 0) { throw "AgentDo installer exited with code $($Proc.ExitCode)" } if (-not (Test-Path $AppExe)) { Copy-Item -Path $InstallerPath -Destination $AppExe -Force } $StartupDir = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\Startup" if (Test-Path $StartupDir) { $ShortcutPath = Join-Path $StartupDir "AgentDo.lnk" $WshShell = New-Object -ComObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($ShortcutPath) $Shortcut.TargetPath = $AppExe $Shortcut.WorkingDirectory = $AppDir $Shortcut.Description = "AgentDo Desktop AI Companion" $Shortcut.Save() Write-Host "[AgentDo] Startup shortcut created: $ShortcutPath" -ForegroundColor Green } Write-Host "[AgentDo] Launching $AppExe ..." -ForegroundColor Green Start-Process -FilePath $AppExe -WorkingDirectory $AppDir Remove-Item -Recurse -Force $TempDir -ErrorAction SilentlyContinue Write-Host "[AgentDo] Installation complete!" -ForegroundColor Green