Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/herdr-t3/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ function Log($msg) { Write-Host "[herdr-t3] $msg" }
function Die($msg) { Write-Host "[herdr-t3] ERROR: $msg" -ForegroundColor Red; exit 1 }

if (-not $Ref) {
# Stable release tags only: a prerelease tag like v1.1.0-rc.1 would fail
# the [version] cast below and must never win auto-selection.
$tags = git ls-remote --tags $RepoUrl "refs/tags/v*" |
ForEach-Object { ($_ -split "/")[-1] } | Where-Object { $_ -notmatch '\^' }
ForEach-Object { ($_ -split "/")[-1] } | Where-Object { $_ -match '^v\d+\.\d+\.\d+$' }
$Ref = $tags | Sort-Object { [version]($_.TrimStart('v')) } | Select-Object -Last 1
if (-not $Ref) { Die "no v* tag found on $RepoUrl" }
if (-not $Ref) { Die "no stable v* tag found on $RepoUrl" }
}
if ($Ref -match '^v[0-9]') {
git ls-remote --exit-code --tags $RepoUrl "refs/tags/$Ref" | Out-Null
Expand All @@ -43,6 +45,7 @@ if (-not (Test-Path (Join-Path $target ".git"))) {
git -C $target fetch --quiet --tags origin
}
git -C $target checkout --quiet $Ref
if ($LASTEXITCODE -ne 0) { Die "git checkout $Ref failed in $target" }
$commit = (git -C $target rev-parse HEAD).Trim()
Log "building $name ($commit)"

Expand Down
17 changes: 12 additions & 5 deletions components/herdr-t3/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ bundle_id_of() { # $1 = .app path -> prints CFBundleIdentifier or nothing
resolve_ref() {
local ref="${1:-}"
if [[ -z "$ref" ]]; then
# Stable release tags only: sort -V would let a prerelease tag like
# v1.1.0-rc.1 win auto-selection.
ref="$(git ls-remote --tags "$REPO_URL" 'refs/tags/v*' \
| awk -F/ '{print $3}' | grep -v '\^' | sort -V | tail -1)"
[[ -n "$ref" ]] || die "no v* tag found on $REPO_URL"
| awk -F/ '{print $3}' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)"
[[ -n "$ref" ]] || die "no stable v* tag found on $REPO_URL"
fi
if [[ "$ref" =~ ^v[0-9] ]]; then
git ls-remote --exit-code --tags "$REPO_URL" "refs/tags/$ref" >/dev/null \
Expand Down Expand Up @@ -76,10 +78,15 @@ stage_app() { # $1 = source .app, $2 = destination .app
pgrep -f "$dst/Contents/MacOS/herdr-t3" >/dev/null 2>&1 \
&& die "herdr-t3 is still running; quit it and retry"
fi
rm -rf "$dst"
fi
ditto "$src" "$dst"
[[ -x "$dst/Contents/MacOS/herdr-t3" ]] || die "staged app has no executable: $dst"
# Stage beside the destination and swap only after the copy verifies, so a
# failed ditto never leaves ~/Applications without the app.
local staging="$dst.staging-$$"
rm -rf "$staging"
ditto "$src" "$staging" || { rm -rf "$staging"; die "ditto failed staging $src"; }
[[ -x "$staging/Contents/MacOS/herdr-t3" ]] || { rm -rf "$staging"; die "staged app has no executable: $staging"; }
rm -rf "$dst"
mv "$staging" "$dst"
# Register with Launch Services so Finder/Spotlight/`open -a` resolve it,
# and unregister the build artifact so it can never win resolution.
[[ -x "$LSREGISTER" ]] && "$LSREGISTER" -f "$dst" >/dev/null 2>&1 || true
Expand Down
10 changes: 8 additions & 2 deletions components/herdr-t3/rollback.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ if [[ -e "$dst" ]]; then
fi
pgrep -f "$dst/Contents/MacOS/herdr-t3" >/dev/null 2>&1 && die "herdr-t3 still running; quit and retry"
fi
rm -rf "$dst"
fi
ditto "$built" "$dst"
# Stage beside the destination and swap only after the copy verifies, so a
# failed ditto never leaves ~/Applications without the app.
staging="$dst.staging-$$"
rm -rf "$staging"
ditto "$built" "$staging" || { rm -rf "$staging"; die "ditto failed staging $built"; }
[[ -x "$staging/Contents/MacOS/herdr-t3" ]] || { rm -rf "$staging"; die "staged app has no executable: $staging"; }
rm -rf "$dst"
mv "$staging" "$dst"
[[ -x "$LSREGISTER" ]] && "$LSREGISTER" -f "$dst" >/dev/null 2>&1 || true
[[ -x "$LSREGISTER" ]] && "$LSREGISTER" -u "$built" >/dev/null 2>&1 || true

Expand Down
14 changes: 11 additions & 3 deletions components/herdr-t3/verify.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ Write-Host "[herdr-t3] start menu: $lnk"
if ($Live) {
if (-not (Get-Process -Name "herdr-t3" -ErrorAction SilentlyContinue)) { Fail "app is not running (run launch.ps1)" }
$sock = if ($env:HERDR_SOCKET) { $env:HERDR_SOCKET } else { Join-Path $env:APPDATA "herdr\herdr.sock" }
$pipe = "\\.\pipe\$sock"
if (-not (Test-Path $sock) -and -not [System.IO.Directory]::Exists($pipe)) {
Fail "herdr endpoint not found: $sock / $pipe (is herdr running?)"
# Windows herdr endpoints are named pipes; Directory.Exists cannot see
# them, so probe the pipe with a short connect instead.
$pipeName = [System.IO.Path]::GetFileName($sock)
$pipeUp = $false
try {
$pipeClient = New-Object System.IO.Pipes.NamedPipeClientPipe('.', $pipeName, [System.IO.Pipes.PipeDirection]::InOut)
try { $pipeClient.Connect(1500); $pipeUp = $true } catch { }
finally { $pipeClient.Dispose() }
} catch { }
if (-not (Test-Path $sock) -and -not $pipeUp) {
Fail "herdr endpoint not found: $sock / \\.\pipe\$pipeName (is herdr running?)"
}
Write-Host "[herdr-t3] live: app running, herdr endpoint present: $sock"
}
9 changes: 8 additions & 1 deletion platforms/windows-11/install-rex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ else {
Expand-Archive -LiteralPath $zipPath -DestinationPath $extractDir -Force

if (Test-Path -LiteralPath $InstallRoot) {
# A running rex.exe locks its directory; stop it first so the
# replace cannot fail halfway and leave a mixed install.
Get-Process -Name 'rex' -ErrorAction SilentlyContinue |
Where-Object { $_.Path -and $_.Path.StartsWith($InstallRoot, [StringComparison]::OrdinalIgnoreCase) } |
Stop-Process -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $InstallRoot -Recurse -Force
}
New-Item -ItemType Directory -Path $InstallRoot -Force | Out-Null
Expand All @@ -87,7 +92,9 @@ else {
}

$newVersion = Get-RexVersion -RexExe $existingExe
Write-Host "ok Rex $($newVersion ?? $release.version) installed -> $existingExe"
$reportedVersion = $newVersion
if (-not $reportedVersion) { $reportedVersion = $release.version }
Write-Host "ok Rex $reportedVersion installed -> $existingExe"
}
finally {
Remove-Item -LiteralPath $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Expand Down
17 changes: 14 additions & 3 deletions platforms/windows-11/user-path.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ if (-not $StateDir) {
function Get-UserPathRaw {
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $false)
try {
if ($key.GetValueNames() -notcontains 'Path') {
# PATH normally exists as REG_EXPAND_SZ; a missing value is
# written back expandable.
return [pscustomobject]@{ Value = ''; Kind = [Microsoft.Win32.RegistryValueKind]::ExpandString }
}
$value = $key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
$kind = $key.GetValueKind('Path')
if ($kind -eq [Microsoft.Win32.RegistryValueKind]::Unknown) {
# PATH normally exists as REG_EXPAND_SZ; a missing value kind means
# the value itself is absent, so write it back expandable.
$kind = [Microsoft.Win32.RegistryValueKind]::ExpandString
}
}
Expand Down Expand Up @@ -136,7 +139,15 @@ if (-not $Apply) {
}

$kept = @($entries | Where-Object { -not (Test-LegacyCargoEntry -Entry $_) })
if (-not $shimPresent) { $kept += $miseShimEntry }
if (-not $shimPresent) {
# A REG_SZ User PATH is never environment-expanded at runtime, so the
# shim entry must be stored pre-expanded there; REG_EXPAND_SZ keeps the
# portable %LOCALAPPDATA% form.
$shimEntry = if ($current.Kind -eq [Microsoft.Win32.RegistryValueKind]::String) {
[Environment]::ExpandEnvironmentVariables($miseShimEntry)
} else { $miseShimEntry }
$kept += $shimEntry
}
$newValue = ($kept -join ';')

if ($newValue -eq $current.Value) {
Expand Down