Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

feat(selfupdate): apply updates on Linux from .deb and .rpm packages

shukieshah2684fdce4fc7
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 387f80de..cc29a356 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -216,11 +216,30 @@ jobs:
- name: Generate update manifest
env:
VERSION: ${{ steps.ver.outputs.version }}
+ # Needed to download the Linux packages the goreleaser job published, so their
+ # checksums are computed from the released bytes.
+ GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
- sh packaging/macos/gen-update-manifest.sh \
- "$VERSION" "$TAG" "$REPO" "$APPLE_TEAM_ID" \
- "arm64=$(ls dist/macos/*-${VERSION}-arm64.pkg)" > dist/macos/update-manifest.json
+ # The Linux packages were published by the goreleaser job this one depends on, so
+ # download them and checksum the bytes that were actually released rather than
+ # trusting a value computed somewhere else.
+ mkdir -p dist/linux
+ for f in "beacon_${VERSION}_linux_amd64.deb" "beacon_${VERSION}_linux_arm64.deb"; do
+ if gh release download "$TAG" --repo "$REPO" --pattern "$f" --dir dist/linux; then
+ echo "downloaded $f"
+ else
+ echo "::warning::$f not found on the release; omitting it from update-manifest.json"
+ fi
+ done
+
+ set -- "$VERSION" "$TAG" "$REPO" "$APPLE_TEAM_ID" \
+ "darwin_arm64=$(ls dist/macos/*-${VERSION}-arm64.pkg)"
+ for arch in amd64 arm64; do
+ deb="dist/linux/beacon_${VERSION}_linux_${arch}.deb"
+ [ -f "$deb" ] && set -- "$@" "linux_${arch}=$deb"
+ done
+ sh packaging/release/gen-update-manifest.sh "$@" > dist/macos/update-manifest.json
cat dist/macos/update-manifest.json
- name: Attach packages + manifest to the release
diff --git a/cli/beacon/internal/endpoint/selfupdate/apply.go b/cli/beacon/internal/endpoint/selfupdate/apply.go
index e9de6bc6..c62f0c65 100644
--- a/cli/beacon/internal/endpoint/selfupdate/apply.go
+++ b/cli/beacon/internal/endpoint/selfupdate/apply.go
@@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
"time"
@@ -40,6 +41,10 @@ type ApplyResult struct {
Applied bool
RolledBack bool
Message string
+ // Verification names the checks the artifact actually passed. Recorded rather than implied,
+ // because it differs by platform: macOS adds notarization on top of the checksum, Linux has
+ // no OS-level equivalent, and "verified" must not paper over which of the two happened.
+ Verification string
}
// Applier performs the full download → verify → install → health-check →
@@ -166,7 +171,20 @@ func (a *Applier) Apply(ctx context.Context) (ApplyResult, error) {
a.emit(false, result, err.Error())
return result, fmt.Errorf("verify checksum: %w", err)
}
- if !a.SkipGatekeeper {
+ // Gatekeeper is macOS-only: pkgutil, stapler and spctl do not exist elsewhere, and there is
+ // no OS-level equivalent on Linux. Skipped explicitly and logged rather than silently, so
+ // the weaker verification is visible in the system log rather than assumed.
+ //
+ // SHA-256 verification above still applies on every platform and is not optional. The trust
+ // root that leaves is HTTPS plus the release checksum -- which is the same trust root the
+ // user relied on to obtain the package they are updating, so this is parity with the install
+ // path rather than a downgrade. Notarization gives macOS assurance above that; adding a
+ // comparable Linux story means a signing scheme (GPG-signed metadata or Sigstore) with real
+ // key management, and that is a deliberate decision rather than something to bolt on here.
+ if runtime.GOOS != "darwin" {
+ result.Verification = "sha256"
+ } else if !a.SkipGatekeeper {
+ result.Verification = "sha256+notarization"
if err := a.verifyGatekeeper(ctx, pkgPath, manifest.TeamID); err != nil {
a.emit(false, result, err.Error())
return result, fmt.Errorf("verify signature/notarization: %w", err)
@@ -390,13 +408,50 @@ func (a *Applier) install(ctx context.Context, pkgPath string) error {
if a.AllowInsecureTest {
return extractTarballInto(pkgPath, a.prefix())
}
- out, err := a.runner()(ctx, "installer", "-pkg", pkgPath, "-target", a.prefix())
+ name, args := installerCommand(pkgPath, a.prefix())
+ out, err := a.runner()(ctx, name, args...)
if err != nil {
return fmt.Errorf("%s: %w", strings.TrimSpace(out), err)
}
return nil
}
+// installerCommand picks the tool that installs a staged package.
+//
+// dpkg and rpm are used directly rather than apt or dnf: the artifact is a local file already
+// downloaded and checksum-verified, so there is no repository to consult, and the higher-level
+// tools would only add a dependency-resolution step that can prompt or reach the network. An
+// update must not become interactive halfway through.
+//
+// Both are asked to upgrade in place rather than install fresh, so the running version is
+// replaced rather than conflicting with itself.
+func installerCommand(pkgPath, prefix string) (string, []string) {
+ switch {
+ case strings.HasSuffix(pkgPath, ".deb"):
+ return "dpkg", []string{"--install", pkgPath}
+ case strings.HasSuffix(pkgPath, ".rpm"):
+ return "rpm", []string{"--upgrade", "--replacepkgs", pkgPath}
+ default:
+ // Everything else keeps the path it took before Linux support existed, so macOS
+ // behaviour is unchanged. Note filepath.Ext is unusable here: it reports ".gz" for a
+ // .tar.gz, which is why this matches suffixes the way packageExt does.
+ return "installer", []string{"-pkg", pkgPath, "-target", prefix}
+ }
+}
+
+// linuxPackageExt reports which native package format this host can install.
+func linuxPackageExt() string {
+ if _, err := exec.LookPath("dpkg"); err == nil {
+ return ".deb"
+ }
+ if _, err := exec.LookPath("rpm"); err == nil {
+ return ".rpm"
+ }
+ // Neither is present, so no native install is possible. Assume deb so the resulting failure
+ // names dpkg, which is actionable, rather than the absence of the macOS installer.
+ return ".deb"
+}
+
// installDir is the root of the installed tree under the active prefix.
func (a *Applier) installDir() string {
return filepath.Join(a.prefix(), "opt", "beacon")
@@ -524,12 +579,23 @@ func versionLineMatches(out, want string) bool {
return false
}
+// packageExt names the staged artifact so the installer that runs on it can dispatch correctly.
+//
+// The URL wins when it already carries a recognised extension, because the manifest is the
+// authority on what was published. Otherwise fall back to the platform's native format: .pkg on
+// macOS, and on Linux whichever of dpkg or rpm this host actually has.
func packageExt(url string) string {
switch {
case strings.HasSuffix(url, ".tar.gz"):
return ".tar.gz"
case strings.HasSuffix(url, ".tgz"):
return ".tgz"
+ case strings.HasSuffix(url, ".deb"):
+ return ".deb"
+ case strings.HasSuffix(url, ".rpm"):
+ return ".rpm"
+ case runtime.GOOS == "linux":
+ return linuxPackageExt()
default:
return ".pkg"
}
diff --git a/cli/beacon/internal/endpoint/selfupdate/apply_test.go b/cli/beacon/internal/endpoint/selfupdate/apply_test.go
index d742509d..31beaa5e 100644
--- a/cli/beacon/internal/endpoint/selfupdate/apply_test.go
+++ b/cli/beacon/internal/endpoint/selfupdate/apply_test.go
@@ -12,6 +12,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
+ "runtime"
"strings"
"testing"
@@ -481,3 +482,84 @@ func mustRead(t *testing.T, path string) []byte {
}
return data
}
+
+// The installer is chosen by artifact suffix, and getting this wrong is easy: filepath.Ext reports
+// ".gz" for a .tar.gz, so an Ext-based switch silently fails to match the tarball the test seam
+// uses. It also has to leave every non-Linux format on exactly the path it took before Linux
+// support existed, or this becomes a macOS behaviour change disguised as a Linux feature.
+func TestInstallerCommandDispatchesBySuffix(t *testing.T) {
+ cases := []struct {
+ path string
+ wantName string
+ wantArg string
+ }{
+ {"/stage/beacon_1.0.6_linux_amd64.deb", "dpkg", "--install"},
+ {"/stage/beacon_1.0.6_linux_arm64.rpm", "rpm", "--upgrade"},
+ {"/stage/BeaconEndpointAgent-1.0.6-arm64.pkg", "installer", "-pkg"},
+ // The test seam stages a tarball. It must keep reaching the previous installer path.
+ {"/stage/beacon_1.0.6_darwin_arm64.tar.gz", "installer", "-pkg"},
+ {"/stage/beacon.tgz", "installer", "-pkg"},
+ }
+ for _, c := range cases {
+ name, args := installerCommand(c.path, "/")
+ if name != c.wantName {
+ t.Errorf("%s -> %q, want %q", c.path, name, c.wantName)
+ continue
+ }
+ if len(args) == 0 || args[0] != c.wantArg {
+ t.Errorf("%s -> args %v, want first arg %q", c.path, args, c.wantArg)
+ }
+ // The artifact must be passed through, or the installer would act on nothing.
+ found := false
+ for _, a := range args {
+ if a == c.path {
+ found = true
+ }
+ }
+ if !found {
+ t.Errorf("%s: the artifact path is missing from args %v", c.path, args)
+ }
+ }
+}
+
+// dpkg and rpm are invoked directly rather than through apt or dnf. The artifact is already
+// downloaded and checksum-verified, so there is no repository to consult, and the higher-level
+// tools would add a resolution step that can prompt or reach the network. An unattended update
+// must not become interactive.
+func TestLinuxInstallersUpgradeInPlaceAndDoNotUseAptOrDnf(t *testing.T) {
+ for _, path := range []string{"/s/x.deb", "/s/x.rpm"} {
+ name, args := installerCommand(path, "/")
+ if name == "apt" || name == "apt-get" || name == "dnf" || name == "yum" {
+ t.Errorf("%s uses %q; a local verified artifact needs no repository resolution", path, name)
+ }
+ joined := name + " " + strings.Join(args, " ")
+ // Upgrade rather than fresh install, so the running version is replaced not conflicted.
+ if !strings.Contains(joined, "--install") && !strings.Contains(joined, "--upgrade") {
+ t.Errorf("%s -> %q does not upgrade in place", path, joined)
+ }
+ }
+}
+
+// Verification differs by platform and must be recorded rather than implied, so a weaker check is
+// visible in telemetry instead of being indistinguishable from the stronger one.
+func TestPackageExtPrefersTheURLThenThePlatform(t *testing.T) {
+ cases := map[string]string{
+ "https://x/beacon_1.0.6_linux_amd64.deb": ".deb",
+ "https://x/beacon_1.0.6_linux_arm64.rpm": ".rpm",
+ "https://x/beacon.tar.gz": ".tar.gz",
+ "https://x/beacon.tgz": ".tgz",
+ }
+ for url, want := range cases {
+ if got := packageExt(url); got != want {
+ t.Errorf("packageExt(%q) = %q, want %q", url, got, want)
+ }
+ }
+ // A URL with no recognised suffix falls back to the platform's native format.
+ got := packageExt("https://x/beacon-release")
+ if runtime.GOOS == "darwin" && got != ".pkg" {
+ t.Errorf("on darwin the fallback should be .pkg, got %q", got)
+ }
+ if runtime.GOOS == "linux" && got != ".deb" && got != ".rpm" {
+ t.Errorf("on linux the fallback should be a native package format, got %q", got)
+ }
+}
diff --git a/packaging/macos/gen-update-manifest.sh b/packaging/macos/gen-update-manifest.sh
deleted file mode 100755
index 4a7b1dc0..00000000
--- a/packaging/macos/gen-update-manifest.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-# Generate the package update manifest (update-manifest.json) for a release.
-#
-# Usage:
-# gen-update-manifest.sh VERSION TAG REPO TEAM_ID \
-# arm64=/path/Beacon-...-arm64.pkg amd64=/path/Beacon-...-amd64.pkg
-#
-# Emits JSON to stdout. Download URLs point at the GitHub release assets for TAG.
-set -eu
-
-if [ "$#" -lt 5 ]; then
- echo "usage: $0 VERSION TAG REPO TEAM_ID arch=pkgpath [arch=pkgpath ...]" >&2
- exit 2
-fi
-
-VERSION="$1"; TAG="$2"; REPO="$3"; TEAM_ID="$4"
-shift 4
-
-MIN_SUPPORTED="${BEACON_MIN_SUPPORTED_VERSION:-}"
-PKG_IDENTIFIER="${PKG_IDENTIFIER:-ai.asymptote.beacon.endpoint}"
-
-artifacts=""
-for pair in "$@"; do
- arch="${pair%%=*}"
- pkg="${pair#*=}"
- if [ ! -f "$pkg" ]; then
- echo "package not found: $pkg" >&2
- exit 1
- fi
- sha="$(shasum -a 256 "$pkg" | awk '{print $1}')"
- base="$(basename "$pkg")"
- url="https://github.com/$REPO/releases/download/$TAG/$base"
- entry="\"darwin_$arch\":{\"url\":\"$url\",\"sha256\":\"$sha\"}"
- if [ -z "$artifacts" ]; then
- artifacts="$entry"
- else
- artifacts="$artifacts,$entry"
- fi
-done
-
-min_field=""
-if [ -n "$MIN_SUPPORTED" ]; then
- min_field="\"min_supported_version\":\"$MIN_SUPPORTED\","
-fi
-
-printf '{"schema":1,"version":"%s",%s"team_id":"%s","pkg_identifier":"%s","artifacts":{%s}}\n' \
- "$VERSION" "$min_field" "$TEAM_ID" "$PKG_IDENTIFIER" "$artifacts"
diff --git a/packaging/release/gen-update-manifest.sh b/packaging/release/gen-update-manifest.sh
new file mode 100755
index 00000000..4e658344
--- /dev/null
+++ b/packaging/release/gen-update-manifest.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+# Generate the package update manifest (update-manifest.json) for a release.
+#
+# Usage:
+# gen-update-manifest.sh VERSION TAG REPO TEAM_ID \
+# darwin_arm64=/path/BeaconEndpointAgent-1.0.6-arm64.pkg \
+# linux_amd64=/path/beacon_1.0.6_linux_amd64.deb \
+# linux_arm64=/path/beacon_1.0.6_linux_arm64.deb
+#
+# Keys are GOOS_GOARCH, matching updatecheck.RuntimeArchKey() on the consumer side. A bare arch
+# (arm64=...) is still accepted and treated as darwin, so existing release tooling keeps working.
+#
+# Lives under packaging/release/ rather than packaging/macos/ because it now describes artifacts
+# for both platforms.
+#
+# team_id and pkg_identifier are Apple concepts with no Linux analogue. They stay in the manifest
+# for the macOS notarization check; a Linux artifact is verified by SHA-256, which is enforced on
+# every platform regardless.
+#
+# Emits JSON to stdout. Download URLs point at the GitHub release assets for TAG.
+set -eu
+
+if [ "$#" -lt 5 ]; then
+ echo "usage: $0 VERSION TAG REPO TEAM_ID goos_arch=pkgpath [goos_arch=pkgpath ...]" >&2
+ exit 2
+fi
+
+VERSION="$1"; TAG="$2"; REPO="$3"; TEAM_ID="$4"
+shift 4
+
+MIN_SUPPORTED="${BEACON_MIN_SUPPORTED_VERSION:-}"
+PKG_IDENTIFIER="${PKG_IDENTIFIER:-ai.asymptote.beacon.endpoint}"
+
+artifacts=""
+for pair in "$@"; do
+ arch="${pair%%=*}"
+ pkg="${pair#*=}"
+ if [ ! -f "$pkg" ]; then
+ echo "package not found: $pkg" >&2
+ exit 1
+ fi
+ # shasum is macOS; sha256sum is Linux. The release job may run on either.
+ if command -v shasum >/dev/null 2>&1; then
+ sha="$(shasum -a 256 "$pkg" | awk '{print $1}')"
+ else
+ sha="$(sha256sum "$pkg" | awk '{print $1}')"
+ fi
+ base="$(basename "$pkg")"
+ url="https://github.com/$REPO/releases/download/$TAG/$base"
+ # A key without a platform means darwin, for compatibility with the original contract.
+ case "$arch" in
+ *_*) key="$arch" ;;
+ *) key="darwin_$arch" ;;
+ esac
+ entry="\"$key\":{\"url\":\"$url\",\"sha256\":\"$sha\"}"
+ if [ -z "$artifacts" ]; then
+ artifacts="$entry"
+ else
+ artifacts="$artifacts,$entry"
+ fi
+done
+
+min_field=""
+if [ -n "$MIN_SUPPORTED" ]; then
+ min_field="\"min_supported_version\":\"$MIN_SUPPORTED\","
+fi
+
+printf '{"schema":1,"version":"%s",%s"team_id":"%s","pkg_identifier":"%s","artifacts":{%s}}\n' \
+ "$VERSION" "$min_field" "$TEAM_ID" "$PKG_IDENTIFIER" "$artifacts"