# Customer installer: PowerShell glue for a checksummed Windows x64 archive; builds nothing. # # .\install.ps1 download and install the latest version (needs CRUMBTRAIL_DOWNLOAD_TOKEN) # .\install.ps1 -Version 0.1.0 install one version # .\install.ps1 -From FILE.zip install a ZIP you already have (SHA256SUMS beside it, or -Sha256) # .\install.ps1 -AcceptLicence accept the licence for an unattended install # .\install.ps1 -NoPathUpdate leave your PATH alone # # Environment: CRUMBTRAIL_DOWNLOAD_BASE (default https://crumbtrail.ai/downloads), CRUMBTRAIL_EDITION (default free), # CRUMBTRAIL_DOWNLOAD_TOKEN, CRUMBTRAIL_SHA256 (expected checksum for -From), CRUMBTRAIL_ACCEPT_LICENCE=1, # CRUMBTRAIL_DOWNLOAD_STALL_SECONDS (default 30: a download slower than 1 KB/s for this long is retried). # Network layout: $BASE/latest, $BASE/// and $BASE///SHA256SUMS. # Everything is checked before the installed program is replaced. The script installs for the current user only: # no administrator rights, no service, no execution-policy change. It never tries to get around a policy that stops it: # if this computer's PowerShell settings refuse to run it, you see PowerShell's own message and nothing is installed. [CmdletBinding()] param( [string]$From, [string]$Version, [string]$InstallDir = (Join-Path $env:LOCALAPPDATA 'Crumbtrail\bin'), [string]$Sha256 = $env:CRUMBTRAIL_SHA256, [switch]$AllowInternal, [switch]$AllowUnsigned, # a build you made yourself, installed from a file without a signed SHA256SUMS list; not shown in the guides [switch]$AcceptLicence, [switch]$NoPathUpdate ) $ErrorActionPreference = 'Stop' # Public key for release signatures (P-256, base64 DER), the same as RELEASE_KEY in install.sh. $ReleaseKey = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEuCpr0ojIQuZGqK06mteZ5u0PU7M/heCZeh3f6EN6dpXUdjFaHj2DFwPboDxHJKqY1AwWOLRtdyLCGZVFfORnrg==' if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) { throw 'Run this installer on Windows.' } if (-not [Environment]::Is64BitOperatingSystem -or $env:PROCESSOR_ARCHITECTURE -eq 'ARM64' -or $env:PROCESSOR_ARCHITEW6432 -eq 'ARM64') { throw 'This package requires Windows on an x64 processor.' } try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } $remote = [string]::IsNullOrEmpty($From) $callerToken = $env:CRUMBTRAIL_DOWNLOAD_TOKEN # restored when we finish; the caller's own state is not ours to change $callerProgress = $ProgressPreference $token = $env:CRUMBTRAIL_DOWNLOAD_TOKEN $edition = if ($env:CRUMBTRAIL_EDITION) { $env:CRUMBTRAIL_EDITION } else { 'free' } $base = if ($env:CRUMBTRAIL_DOWNLOAD_BASE) { $env:CRUMBTRAIL_DOWNLOAD_BASE } else { 'https://crumbtrail.ai/downloads' } $base = $base.TrimEnd('/') $signIn = 'Sign in at https://crumbtrail.ai/download and generate a new install command.' # The checksum list must carry Crumbtrail's release signature (an ECDSA P-256 signature over the list, as install.sh checks it). function Test-ReleaseSignature([string]$List, [string]$Signature, [string]$PublicKey = $ReleaseKey) { $ecdsa = [Security.Cryptography.ECDsa]::Create() if (-not ($ecdsa.GetType().GetMethod('ImportSubjectPublicKeyInfo')) -or -not ('System.Security.Cryptography.DSASignatureFormat' -as [type])) { throw 'This PowerShell cannot check the signature on SHA256SUMS. Install from a file with PowerShell 7 or newer.' } $read = 0 $ecdsa.ImportSubjectPublicKeyInfo([Convert]::FromBase64String($PublicKey), [ref]$read) $ok = $ecdsa.VerifyData([IO.File]::ReadAllBytes($List), [IO.File]::ReadAllBytes($Signature), [Security.Cryptography.HashAlgorithmName]::SHA256, [Security.Cryptography.DSASignatureFormat]::Rfc3279DerSequence) if (-not $ok) { throw 'SHA256SUMS is not signed by Crumbtrail. Nothing was installed.' } Write-Output 'Signature OK' } # Shows the licence for the edition being installed and asks for a yes unless acceptance was given up front. function Confirm-Licence { param([Parameter(Mandatory = $true)][ValidateSet('free', 'paid')][string]$Kind) if ($Kind -eq 'paid') { Write-Output 'Crumbtrail Paid Edition Software Licence' Write-Output 'https://crumbtrail.ai/legal/paid-edition-licence' Write-Output 'Where you have a signed agreement with Crumbtrail, that agreement governs your use.' } else { Write-Output 'Crumbtrail Free Edition Software Licence Agreement' Write-Output 'https://crumbtrail.ai/legal/free-edition-licence' } Write-Output 'Use is subject to this licence and the Crumbtrail Privacy Policy: https://crumbtrail.ai/legal/privacy-policy' if (-not ($AcceptLicence -or $env:CRUMBTRAIL_ACCEPT_LICENCE -eq '1')) { if ([Console]::IsInputRedirected) { throw 'Licence acceptance required; use -AcceptLicence or CRUMBTRAIL_ACCEPT_LICENCE=1 for an unattended install.' } $answer = Read-Host 'Accept the licence? [y/N]' if ($answer -notmatch '^(y|yes)$') { throw 'Licence not accepted; nothing was installed.' } } } if ($remote) { if ($base -notmatch '^https://' -and $base -notmatch '^http://(localhost|127\.0\.0\.1|\[::1\])(:[0-9]+)?(/|$)') { throw 'Downloads require HTTPS except on this computer.' } if ($edition -notin @('free', 'full', 'full-no-reports')) { throw 'Unknown edition.' } if ($Version -and $Version -notmatch '^[0-9A-Za-z._-]+$') { throw "Unexpected version `"$Version`"." } if (-not $token) { throw $signIn } if ($token -notmatch '^[a-f0-9]{64}$') { throw "The download token is not valid. $signIn" } Confirm-Licence $(if ($edition -eq 'free') { 'free' } else { 'paid' }) } # Replaces every file in $Plan (items with Src and Dst) together or not at all. Nothing changes until the whole plan, including which # destinations already exist, is known. Then each new file is staged beside its destination as .ct-new, each old file is moved aside as # .ct-old, and the new file is moved in. Rollback runs in a finally block, so it also runs when the pipeline is cancelled (Ctrl+C), and it # works from the plan and the disk: an old file is restored only when its .ct-old exists, a destination is deleted only when the plan said # it did not exist before, and a destination that existed is never deleted. After success the backups are removed as a separate step; # a backup that Windows will not delete because the old program is still running is renamed .ct-keep-* so its bytes are kept. function Install-OwnedFiles { param([Parameter(Mandatory = $true)][object[]]$Plan) $ErrorActionPreference = 'Stop' foreach ($step in $Plan) { $old = $step.Dst + '.ct-old' if (Test-Path -LiteralPath $old) { throw "$old is left over from an earlier interrupted update and holds your earlier version. Move it back over $($step.Dst) (or delete it) and run the command again. Nothing was changed." } $step.Had = [bool](Test-Path -LiteralPath $step.Dst) $dir = Split-Path -Parent $step.Dst if (Test-Path -LiteralPath $dir) { foreach ($kept in @(Get-ChildItem -LiteralPath $dir -Filter (([IO.Path]::GetFileName($step.Dst)) + '.ct-keep-*') -ErrorAction SilentlyContinue)) { Remove-Item -Force -ErrorAction SilentlyContinue -LiteralPath $kept.FullName } } } $committed = $false $failure = $null $restored = $true try { foreach ($step in $Plan) { New-Item -ItemType Directory -Force -Path (Split-Path -Parent $step.Dst) | Out-Null Copy-Item -Force -LiteralPath $step.Src -Destination ($step.Dst + '.ct-new') } foreach ($step in $Plan) { if ($step.Had) { Move-Item -Force -LiteralPath $step.Dst -Destination ($step.Dst + '.ct-old') } Move-Item -Force -LiteralPath ($step.Dst + '.ct-new') -Destination $step.Dst } $committed = $true } catch { $failure = $_ } finally { if (-not $committed) { foreach ($step in $Plan) { try { if ($step.Had) { if (Test-Path -LiteralPath ($step.Dst + '.ct-old')) { Move-Item -Force -LiteralPath ($step.Dst + '.ct-old') -Destination $step.Dst } } else { Remove-Item -Force -ErrorAction SilentlyContinue -LiteralPath $step.Dst } Remove-Item -Force -ErrorAction SilentlyContinue -LiteralPath ($step.Dst + '.ct-new') } catch { $restored = $false } } if (-not $failure) { if ($restored) { Write-Warning 'Interrupted. Your earlier installation was put back exactly as it was.' } else { Write-Warning 'Interrupted, and the earlier files could not all be put back. Files ending in .ct-old next to the programs hold your earlier versions.' } } } } if ($failure) { if ($restored) { throw 'Could not replace the installed files. Your earlier installation was put back exactly as it was. If Crumbtrail is running, close it and run the command again.' } throw 'Could not replace the installed files, and could not fully put the earlier ones back. Files ending in .ct-old next to the programs hold your earlier versions.' } foreach ($step in $Plan) { if (-not $step.Had) { continue } $old = $step.Dst + '.ct-old' try { Remove-Item -Force -LiteralPath $old } catch { try { Move-Item -Force -LiteralPath $old -Destination ($step.Dst + '.ct-keep-' + [Guid]::NewGuid().ToString('N').Substring(0, 8)) } catch { Write-Warning "Could not remove $old; it holds your previous version and is safe to delete once Crumbtrail is closed." } } } } # One try of a download into $Part, continuing after $Have bytes when that is above 0. Returns @{ Done; Status; Why }: Done is $true when # $Part holds the whole file; otherwise Why says what went wrong in plain words, and Status is the site's answer (0 for none). # Headers must arrive within 15 s plus the stall limit; after that a transfer below 1 KB/s for $Stall seconds counts as stalled. function Receive-ReleaseOnce([string]$Url, [string]$Part, [long]$Have, [int]$Stall, [bool]$Progress) { Add-Type -AssemblyName System.Net.Http $handler = New-Object System.Net.Http.HttpClientHandler $handler.AllowAutoRedirect = $false $client = New-Object System.Net.Http.HttpClient($handler) $client.Timeout = [System.Threading.Timeout]::InfiniteTimeSpan $request = New-Object System.Net.Http.HttpRequestMessage([System.Net.Http.HttpMethod]::Get, $Url) [void]$request.Headers.TryAddWithoutValidation('Authorization', "Bearer $token") if ($Have -gt 0) { $request.Headers.Range = New-Object System.Net.Http.Headers.RangeHeaderValue($Have, $null) } $response = $null; $out = $null; $limit = $null; $drew = $false try { $limit = New-Object System.Threading.CancellationTokenSource $limit.CancelAfter([TimeSpan]::FromSeconds(15 + $Stall)) try { $response = $client.SendAsync($request, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead, $limit.Token).GetAwaiter().GetResult() } catch { return @{ Done = $false; Status = 0; Why = 'the download site could not be reached' } } # Headers are in: the body is bounded by the stall check below, so the header limit is switched off and can never cut a long # download short. (Measured 2026-11-17 on Windows PowerShell 5.1, .NET Framework 4.8.1: a 120 MB, 68 s download finished either way.) $limit.CancelAfter([System.Threading.Timeout]::InfiniteTimeSpan) $status = [int]$response.StatusCode if ($status -eq 416 -and $Have -gt 0) { return @{ Done = $true; Status = 416 } } # the earlier try already received the whole file; the checksum still checks it if ($status -ne 200 -and $status -ne 206) { return @{ Done = $false; Status = $status; Why = 'the download site is busy' } } $start = 0L if ($status -eq 206) { $range = $response.Content.Headers.ContentRange if (-not $range -or $range.From -ne $Have) { return @{ Done = $false; Status = $status; Why = 'the download site could not continue the earlier download'; Restart = $true } } $start = $Have } $total = $null if ($null -ne $response.Content.Headers.ContentLength) { $total = $start + [long]$response.Content.Headers.ContentLength } $mode = if ($start -gt 0) { [IO.FileMode]::Append } else { [IO.FileMode]::Create } $out = [IO.File]::Open($Part, $mode, [IO.FileAccess]::Write) $stream = $response.Content.ReadAsStreamAsync().GetAwaiter().GetResult() $buffer = New-Object byte[] 65536 $got = $start $windowStart = [DateTime]::UtcNow; $windowBytes = 0L; $lastDraw = [DateTime]::MinValue while ($true) { $read = $stream.ReadAsync($buffer, 0, $buffer.Length) try { $arrived = $read.Wait([TimeSpan]::FromSeconds($Stall)) } catch { return @{ Done = $false; Status = $status; Why = 'the connection dropped' } } if (-not $arrived) { return @{ Done = $false; Status = $status; Why = "the download stopped or slowed below 1 KB/s for $Stall seconds" } } $n = $read.Result if ($n -eq 0) { break } $out.Write($buffer, 0, $n); $got += $n; $windowBytes += $n $now = [DateTime]::UtcNow if (($now - $windowStart).TotalSeconds -ge $Stall) { if ($windowBytes -lt 1024L * $Stall) { return @{ Done = $false; Status = $status; Why = "the download stopped or slowed below 1 KB/s for $Stall seconds" } } $windowStart = $now; $windowBytes = 0L } if ($Progress -and ($now - $lastDraw).TotalSeconds -ge 1) { Show-ProgressLine $got $total; $drew = $true; $lastDraw = $now } } if ($Progress -and $drew) { Show-ProgressLine $got $total } if ($null -ne $total -and $got -lt $total) { return @{ Done = $false; Status = $status; Why = 'the connection dropped' } } return @{ Done = $true; Status = $status } } finally { if ($drew) { Write-Host '' } if ($out) { $out.Dispose() } if ($response) { $response.Dispose() } if ($limit) { $limit.Dispose() } $client.Dispose() } } function Show-ProgressLine([long]$Got, $Total) { $mb = '{0:0.0}' -f ($Got / 1MB) if ($Total -and $Total -ge $Got) { Write-Host -NoNewline ("`r $mb of {0:0.0} MB ({1}%) " -f ($Total / 1MB), [math]::Floor($Got * 100 / $Total)) } else { Write-Host -NoNewline "`r $mb MB " } } # The token travels only in an in-process header. A redirect is a failure, so it can never be forwarded. A dropped or stalled download is # tried up to 4 times and continues from the bytes already received when the site allows it; the checksum below still checks every byte. # A progress line is drawn for the big file only when the output is a console and not CI. function Get-Release([string]$Url, [string]$Dest, [string]$What, [switch]$Progress) { $stallText = if ($env:CRUMBTRAIL_DOWNLOAD_STALL_SECONDS) { $env:CRUMBTRAIL_DOWNLOAD_STALL_SECONDS } else { '30' } if ($stallText -notmatch '^[0-9]{1,6}$' -or [int]$stallText -eq 0) { throw 'CRUMBTRAIL_DOWNLOAD_STALL_SECONDS must be a whole number of seconds above 0.' } $stall = [int]$stallText $draw = $Progress -and -not [Console]::IsOutputRedirected -and -not $env:CI $part = $Dest + '.part' if (Test-Path -LiteralPath $part) { Remove-Item -Force -LiteralPath $part } $tries = 4; $pause = 1 for ($try = 1; ; $try++) { $have = 0L if (Test-Path -LiteralPath $part) { $have = (Get-Item -LiteralPath $part).Length } $result = Receive-ReleaseOnce $Url $part $have $stall $draw if ($result.Done) { Move-Item -Force -LiteralPath $part -Destination $Dest; return } $status = $result.Status $why = $result.Why $busy = $status -eq 408 -or $status -eq 429 -or ($status -ge 500 -and $status -lt 600) if ($status -ne 0 -and $status -ne 200 -and $status -ne 206 -and -not $busy) { if (Test-Path -LiteralPath $part) { Remove-Item -Force -LiteralPath $part } if ($status -eq 404) { throw "$What is not published yet. Nothing was installed. Your command still works; run it again after the next release." } if ($status -eq 401 -or $status -eq 403) { throw "Download refused. $signIn" } if ($status -ge 300 -and $status -lt 400) { throw 'The download site redirected the request, which is refused for your safety. Nothing was installed.' } if ($status -eq 416) { $why = 'the download site could not continue the earlier download' } else { throw "The download site answered $status. Nothing was installed; try again later." } } if ($result.Restart -and (Test-Path -LiteralPath $part)) { Remove-Item -Force -LiteralPath $part } if ($try -ge $tries) { if (Test-Path -LiteralPath $part) { Remove-Item -Force -LiteralPath $part } if ($busy) { throw "The download site is busy and answered $status. Nothing was installed; try again later." } if ($status -eq 0) { throw 'Could not reach the download site. Nothing was installed; check your network and run the command again.' } throw ($why.Substring(0, 1).ToUpper() + $why.Substring(1) + ". It did not finish after $tries tries. Nothing was installed; check your network and run the command again.") } $next = if ((Test-Path -LiteralPath $part) -and (Get-Item -LiteralPath $part).Length -gt 0) { 'Continuing where it stopped' } else { 'Starting again' } Write-Host "The download was interrupted: $why. $next in $pause s (try $($try + 1) of $tries)." Start-Sleep -Seconds $pause $pause *= 2 } } if ($remote) { $ProgressPreference = 'SilentlyContinue' } # Windows PowerShell 5.1 draws a progress bar that slows large downloads $work = Join-Path ([IO.Path]::GetTempPath()) ('crumbtrail-install-' + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $work | Out-Null try { if ($remote) { if (-not $Version) { Get-Release "$base/latest" (Join-Path $work 'latest') 'A release' $Version = (Get-Content -Raw -LiteralPath (Join-Path $work 'latest')).Trim() } if ($Version -notmatch '^[0-9A-Za-z._-]+$') { throw "Unexpected version `"$Version`"." } $prefix = if ($edition -eq 'free') { 'crumbtrail-free' } else { 'crumbtrail-paid' } $name = "$prefix-$Version-windows-x86_64.zip" Write-Output "Downloading $name" $archive = Join-Path $work $name Get-Release "$base/$Version/$edition/$name" $archive "A Windows build of version $Version" -Progress $sums = Join-Path $work 'SHA256SUMS' Get-Release "$base/$Version/$edition/SHA256SUMS" $sums "The checksum list for version $Version" # Last download done: nothing extracted or run below ever sees the token. $token = $null Remove-Item Env:CRUMBTRAIL_DOWNLOAD_TOKEN -ErrorAction SilentlyContinue $Sha256 = $null $internalOk = $false } else { $archive = (Resolve-Path -LiteralPath $From).Path $name = [IO.Path]::GetFileName($archive) $sums = Join-Path ([IO.Path]::GetDirectoryName($archive)) 'SHA256SUMS' $internalOk = [bool]$AllowInternal if (-not $AllowUnsigned) { if (-not (Test-Path -LiteralPath $sums)) { throw 'There is no SHA256SUMS next to the archive. Put the signed list beside it.' } if (-not (Test-Path -LiteralPath "$sums.sig")) { throw 'SHA256SUMS has no signature. Put SHA256SUMS.sig beside it, as sent by Crumbtrail. Nothing was installed.' } Test-ReleaseSignature $sums "$sums.sig" $Sha256 = $null # the signed list decides, not a checksum typed in by hand } else { Write-Warning 'This package has no signature, so nothing proves it came from Crumbtrail. Go on only if Crumbtrail sent it to you directly or you built it yourself. Otherwise put SHA256SUMS.sig beside it and run again without -AllowUnsigned.' } # A paid package shows the paid licence before anything is unpacked, like the download route does. if ($name -like 'crumbtrail-paid-*') { Confirm-Licence 'paid' } } if (-not $Sha256) { $entries = @(Get-Content -LiteralPath $sums | Where-Object { $_ -match '^([a-fA-F0-9]{64})\s+\*?(.+)$' -and $Matches[2] -ceq $name }) if ($entries.Count -ne 1) { throw 'SHA256SUMS must contain exactly one entry for this archive.' } $Sha256 = ($entries[0] -split '\s+', 2)[0] } if ($Sha256 -notmatch '^[a-fA-F0-9]{64}$' -or (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash -ine $Sha256) { throw 'Archive checksum mismatch. Nothing was installed.' } Write-Output 'Checksum OK' Add-Type -AssemblyName System.IO.Compression.FileSystem $zip = [IO.Compression.ZipFile]::OpenRead($archive) try { foreach ($entry in $zip.Entries) { if ($entry.FullName -match '(^|/)\.\.(/|$)|\\|:|^/' -or (($entry.ExternalAttributes -shr 16) -band 0xF000) -eq 0xA000) { throw 'Archive contains an unsafe path or link.' } } } finally { $zip.Dispose() } $unpacked = Join-Path $work 'x' [IO.Compression.ZipFile]::ExtractToDirectory($archive, $unpacked) $folders = @(Get-ChildItem -LiteralPath $unpacked -Directory) if ($folders.Count -ne 1 -or $folders[0].Name -notmatch '^crumbtrail-[a-zA-Z0-9._-]+$') { throw 'Unexpected archive layout.' } $package = $folders[0].FullName $manifest = Get-Content -Raw -LiteralPath (Join-Path $package 'manifest.json') | ConvertFrom-Json if ($manifest.format -ne 1 -or $manifest.os -ne 'windows' -or $manifest.arch -ne 'x86_64') { throw 'Package manifest does not match Windows x64.' } if ($manifest.edition -eq 'internal' -and -not $internalOk) { throw 'Internal full packages require -AllowInternal; this is not a Free download.' } if ($manifest.edition -notin @('free', 'internal', 'paid')) { throw 'Unknown package edition.' } if ($remote -and $edition -eq 'free' -and $manifest.edition -ne 'free') { throw 'A Free download must hold a Free package.' } # The licence shown must be the licence of what is installed: paid only for a paid package, and a paid package only after it. $paidName = $name -like 'crumbtrail-paid-*' if ($remote) { $paidName = $edition -ne 'free' } if ($paidName -and $manifest.edition -ne 'paid') { throw 'This is not a Crumbtrail paid package.' } if (-not $paidName -and $manifest.edition -eq 'paid') { throw 'Install a paid package under the file name it came with (crumbtrail-paid-...).' } if ($manifest.edition -eq 'free' -and (Test-Path -LiteralPath (Join-Path $package 'crumbtrail-cloud.exe'))) { throw 'A Free package cannot contain the team service.' } if (-not (Test-Path -LiteralPath (Join-Path $package 'sbom.cdx.json'))) { throw 'Package bill of materials is missing.' } if ($manifest.edition -eq 'paid' -and -not (Test-Path -LiteralPath (Join-Path $package 'LICENCE.md'))) { throw 'This package has no licence file. Nothing was installed.' } $files = @('crumbtrail.exe') if ($manifest.edition -in @('internal', 'paid')) { $files += 'crumbtrail-cloud.exe' } foreach ($line in Get-Content -LiteralPath (Join-Path $package 'SHA256SUMS')) { if ($line -notmatch '^([a-fA-F0-9]{64})\s+\*?(.+)$') { throw 'Invalid payload checksum.' } $digest = $Matches[1]; $relative = $Matches[2] if ($relative -match '(^|/)\.\.(/|$)|\\|:|^/') { throw 'Unsafe payload path.' } if ((Get-FileHash -LiteralPath (Join-Path $package $relative) -Algorithm SHA256).Hash -ine $digest) { throw "Payload checksum mismatch: $relative" } } if ($manifest.signature -eq 'verified-by-hook') { foreach ($file in $files) { if ((Get-AuthenticodeSignature -LiteralPath (Join-Path $package $file)).Status -ne 'Valid') { throw "Invalid Windows signature: $file" } } } $program = Join-Path $package 'crumbtrail.exe' $reported = & $program --version if ($LASTEXITCODE -ne 0 -or ($reported -split '\s+')[1] -ne $manifest.version) { throw 'Package version check failed.' } if ($remote -and $manifest.version -ne $Version) { throw "The package is version $($manifest.version) but version $Version was requested. Nothing was installed." } # Every check has passed. Replace every owned file together or not at all (see Install-OwnedFiles). $plan = @() foreach ($file in $files) { $plan += ,@{ Src = (Join-Path $package $file); Dst = (Join-Path $InstallDir $file) } } $notices = Join-Path $package 'THIRD_PARTY_NOTICES.md' if (Test-Path -LiteralPath $notices -PathType Leaf) { $plan += ,@{ Src = $notices; Dst = (Join-Path $InstallDir 'THIRD_PARTY_NOTICES.md') } } $relaySource = Join-Path $package 'relay' if (Test-Path -LiteralPath $relaySource) { foreach ($item in @(Get-ChildItem -LiteralPath $relaySource -Recurse -File)) { $relative = $item.FullName.Substring($relaySource.Length).TrimStart('\', '/') $plan += ,@{ Src = $item.FullName; Dst = (Join-Path (Join-Path $InstallDir 'relay') $relative) } } } New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null Install-OwnedFiles -Plan $plan Write-Output "Installed Crumbtrail $($manifest.version) into $InstallDir" if (Test-Path -LiteralPath (Join-Path $InstallDir 'THIRD_PARTY_NOTICES.md')) { Write-Output "Open-source notices: $(Join-Path $InstallDir 'THIRD_PARTY_NOTICES.md')" } if ($NoPathUpdate) { Write-Output "Add $InstallDir to your PATH to run crumbtrail from any folder." } else { $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true) try { $current = [string]$key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) $kind = [Microsoft.Win32.RegistryValueKind]::ExpandString try { $kind = $key.GetValueKind('Path') } catch { } $want = $InstallDir.TrimEnd('\') $entries = @($current -split ';' | Where-Object { $_ }) $known = @($entries | Where-Object { [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\') -ieq $want }) if ($known.Count -eq 0) { $key.SetValue('Path', ((@($entries) + $InstallDir) -join ';'), $kind) try { [Environment]::SetEnvironmentVariable('CRUMBTRAIL_PATH_REFRESH', $null, 'User') } catch { } Write-Output "Added $InstallDir to your PATH." } } finally { $key.Close() } if (@($env:Path -split ';' | Where-Object { $_.TrimEnd('\') -ieq $InstallDir.TrimEnd('\') }).Count -eq 0) { $env:Path = "$InstallDir;$env:Path" } Write-Output 'New terminals find crumbtrail. Next: crumbtrail desk serve' } } finally { $ProgressPreference = $callerProgress if ($callerToken) { $env:CRUMBTRAIL_DOWNLOAD_TOKEN = $callerToken } else { Remove-Item Env:CRUMBTRAIL_DOWNLOAD_TOKEN -ErrorAction SilentlyContinue } Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -LiteralPath $work }