# A2 Tprompt installer for Windows. # # irm https://a2tprompt.com/install.ps1 | iex # # Downloads the latest A2 Tprompt installer from GitHub (a2-stuff/a2-tprompt-releases), checks its # SHA-256 checksum when the release has one, and installs it for the current user (no admin rights). # # Options, set before running: # $env:A2_TPROMPT_VERSION = '0.2.0' install that version instead of the latest # $env:A2_TPROMPT_UNINSTALL = '1' uninstall instead $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest is much faster without the progress bar [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Repo = 'a2-stuff/a2-tprompt-releases' $AppDir = Join-Path $env:LOCALAPPDATA 'Programs\A2 Tprompt' $Headers = @{ 'User-Agent' = 'a2-tprompt-installer'; 'Accept' = 'application/vnd.github+json' } function Say($text) { Write-Host " $text" } function Fail($text) { Write-Host " $text" -ForegroundColor Red; throw $text } Write-Host '' Write-Host ' A2 Tprompt' -ForegroundColor White if ($env:A2_TPROMPT_UNINSTALL -eq '1') { $uninstaller = Join-Path $AppDir 'Uninstall A2 Tprompt.exe' if (-not (Test-Path $uninstaller)) { Fail 'A2 Tprompt is not installed for this user.' } Get-Process 'A2 Tprompt' -ErrorAction SilentlyContinue | Stop-Process -Force Start-Process -FilePath $uninstaller -ArgumentList '/S' -Wait Say 'Uninstalled. Your settings and scripts are kept in %APPDATA%\A2 Tprompt; delete that folder to remove them too.' return } if ([Environment]::OSVersion.Version.Build -lt 19041) { Fail 'A2 Tprompt needs Windows 10 version 2004 or later, or Windows 11.' } $url = if ($env:A2_TPROMPT_VERSION) { "https://api.github.com/repos/$Repo/releases/tags/v$($env:A2_TPROMPT_VERSION.TrimStart('v'))" } else { "https://api.github.com/repos/$Repo/releases/latest" } try { $release = Invoke-RestMethod -Uri $url -Headers $Headers } catch { Fail "Could not find that release on GitHub ($url). Check the version and your internet connection." } $asset = $release.assets | Where-Object { $_.name -match '^A2-Tprompt-Setup-[\d.]+\.exe$' } | Select-Object -First 1 if (-not $asset) { Fail "Release $($release.tag_name) has no Windows installer." } $file = Join-Path ([IO.Path]::GetTempPath()) $asset.name Say "Downloading $($asset.name) ($([math]::Round($asset.size / 1MB)) MB)..." Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $file -Headers @{ 'User-Agent' = 'a2-tprompt-installer' } # Check the download against the release's checksum list, when there is one. $sums = $release.assets | Where-Object { $_.name -match '^SHA256SUMS' -and $_.name -match 'windows' } | Select-Object -First 1 if ($sums) { $list = (Invoke-WebRequest -Uri $sums.browser_download_url -Headers @{ 'User-Agent' = 'a2-tprompt-installer' } -UseBasicParsing).Content if ($list -is [byte[]]) { $list = [Text.Encoding]::UTF8.GetString($list) } $expected = ($list -split "`n" | Where-Object { $_ -match [regex]::Escape($asset.name) } | Select-Object -First 1) -replace '\s.*$', '' $actual = (Get-FileHash -Algorithm SHA256 -Path $file).Hash if (-not $expected) { Fail 'The checksum list does not include the installer. Not installing.' } if ($expected.Trim().ToUpper() -ne $actual.ToUpper()) { Remove-Item $file -Force; Fail 'Checksum does not match. The download may be damaged; not installing.' } Say 'Checksum OK.' } else { Say 'This release has no checksum list; skipping the check.' } Get-Process 'A2 Tprompt' -ErrorAction SilentlyContinue | Stop-Process -Force Say 'Installing...' Start-Process -FilePath $file -ArgumentList '/S' -Wait Remove-Item $file -Force -ErrorAction SilentlyContinue $exe = Join-Path $AppDir 'A2 Tprompt.exe' if (-not (Test-Path $exe)) { Fail 'The installer finished but A2 Tprompt was not found. Try the installer from https://a2tprompt.com/install' } Say "Installed A2 Tprompt $($release.tag_name.TrimStart('v')). It's in the Start menu, and it updates itself." Say 'Starting it now: look for the icon in the system tray. Ctrl+Alt+Space starts listening.' Start-Process -FilePath $exe Write-Host ''