<# .SYNOPSIS Deployr bootstrap. Downloads the right binary for this machine, verifies it, installs it, and opens the UI. .DESCRIPTION Designed to be run straight off the web, the way winutil is: irm https://git.starwarslab.us/ATOM_IT/Deployr/raw/branch/main/scripts/install.ps1 | iex With no arguments it installs deployr and opens the point-and-click UI. To pass arguments through instead, create a scriptblock: & ([scriptblock]::Create((irm ))) install @standard Or set $env:DEPLOYR_ARGS before piping to iex: $env:DEPLOYR_ARGS = 'install chrome 7zip'; irm | iex .PARAMETER DeployrArgs Arguments to pass to deployr. Defaults to opening the UI. .PARAMETER Version Release tag to install. Defaults to the latest release. .PARAMETER InstallOnly Install the binary and exit without running anything. #> [CmdletBinding()] param( [Parameter(ValueFromRemainingArguments = $true)] [string[]]$DeployrArgs, [string]$Version = "latest", [switch]$InstallOnly ) $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" # Invoke-WebRequest is ~10x faster without the progress bar $Repo = "https://git.starwarslab.us/ATOM_IT/Deployr" $Dir = Join-Path $env:ProgramData "Deployr" $Exe = Join-Path $Dir "deployr.exe" function Write-Step { param([string]$Message) Write-Host " $Message" -ForegroundColor Cyan } function Write-Ok { param([string]$Message) Write-Host " $Message" -ForegroundColor Green } Write-Host "" Write-Host " Deployr bootstrap" -ForegroundColor White Write-Host " ------------------------------------------------" -ForegroundColor DarkGray # --- privileges --------------------------------------------------------- # Installing software machine-wide needs an elevated token. Relaunch rather # than failing halfway through a run. $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal($identity) if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Step "Elevating..." $argLine = if ($DeployrArgs) { ($DeployrArgs -join ' ') } else { '' } # -File cannot be used here: this script may only exist in memory. Re-fetch # it in the elevated process instead. (-Verb RunAs with -File also fails # silently for a script on a mapped drive.) $bootstrap = "`$env:DEPLOYR_ARGS='$argLine'; irm $Repo/raw/branch/main/scripts/install.ps1 | iex" $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($bootstrap)) Start-Process -FilePath "powershell.exe" -Verb RunAs -ArgumentList @( "-NoProfile", "-ExecutionPolicy", "Bypass", "-NoExit", "-EncodedCommand", $encoded ) return } # Arguments arrive through the environment when the script was piped to iex. if (-not $DeployrArgs -and $env:DEPLOYR_ARGS) { $DeployrArgs = $env:DEPLOYR_ARGS -split '\s+' | Where-Object { $_ } } # --- architecture ------------------------------------------------------- $arch = switch ($env:PROCESSOR_ARCHITECTURE) { "AMD64" { "amd64" } "ARM64" { "arm64" } "x86" { if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { throw "32-bit Windows is not supported" } } default { throw "unsupported architecture: $env:PROCESSOR_ARCHITECTURE" } } $asset = "deployr_windows_$arch.exe" Write-Step "Platform: windows/$arch" # --- resolve the release ------------------------------------------------ # "latest" is not a real download path in Gitea, so resolve it through the API # and take the asset URLs the release actually published. $apiRepo = "$($Repo -replace '/([^/]+)/([^/]+)$', '/api/v1/repos/$1/$2')" $releaseUrl = if ($Version -eq "latest") { "$apiRepo/releases/latest" } else { "$apiRepo/releases/tags/$Version" } Write-Step "Resolving release ($Version) ..." $release = Invoke-RestMethod -Uri $releaseUrl -UseBasicParsing -TimeoutSec 60 $assetUrl = ($release.assets | Where-Object { $_.name -eq $asset }).browser_download_url $sumsUrl = ($release.assets | Where-Object { $_.name -eq "SHA256SUMS" }).browser_download_url if (-not $assetUrl) { throw "release $($release.tag_name) has no asset named $asset" } Write-Ok "Release $($release.tag_name)" New-Item -ItemType Directory -Force -Path $Dir | Out-Null # --- download ----------------------------------------------------------- $tmp = Join-Path $env:TEMP "deployr-$([guid]::NewGuid().ToString('N')).exe" try { Write-Step "Downloading $asset ..." Invoke-WebRequest -Uri $assetUrl -OutFile $tmp -UseBasicParsing -TimeoutSec 300 # Checksums ship with every release; verify when we can reach them, but do # not fail the whole bootstrap if only the sums file is missing. $expected = $null if ($sumsUrl) { try { $sums = (Invoke-WebRequest -Uri $sumsUrl -UseBasicParsing -TimeoutSec 60).Content foreach ($line in $sums -split "`n") { $parts = ($line.Trim() -split '\s+') if ($parts.Count -ge 2 -and ($parts[-1] -replace '^\*|^\./', '') -eq $asset) { $expected = $parts[0] } } } catch { Write-Warning " could not fetch SHA256SUMS: $($_.Exception.Message)" } } if ($expected) { $actual = (Get-FileHash $tmp -Algorithm SHA256).Hash.ToLower() if ($actual -ne $expected.ToLower()) { throw "checksum mismatch for ${asset}: expected $expected, got $actual" } Write-Ok "Checksum verified" } # A running deployr.exe cannot be overwritten; move it aside instead. if (Test-Path $Exe) { try { Remove-Item $Exe -Force } catch { Move-Item $Exe "$Exe.old" -Force -ErrorAction SilentlyContinue } } Move-Item $tmp $Exe -Force Write-Ok "Installed to $Exe" } finally { if (Test-Path $tmp) { Remove-Item $tmp -Force -ErrorAction SilentlyContinue } } # --- PATH --------------------------------------------------------------- $machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine") if ($machinePath -notlike "*$Dir*") { [Environment]::SetEnvironmentVariable("Path", "$machinePath;$Dir", "Machine") Write-Ok "Added $Dir to the system PATH" } if ($env:Path -notlike "*$Dir*") { $env:Path = "$env:Path;$Dir" } Write-Host " ------------------------------------------------" -ForegroundColor DarkGray & $Exe version Write-Host "" if ($InstallOnly) { Write-Host " Run 'deployr ui' for the interface, or 'deployr --help' for commands." -ForegroundColor DarkGray return } if (-not $DeployrArgs) { $DeployrArgs = @("ui") } & $Exe @DeployrArgs exit $LASTEXITCODE