#!/usr/bin/env bash # Installs offrig and its bundled Linux offrigd sidecars from a GitHub release, # on macOS or Linux: # # curl -fsSL https://offrig.dev/install.sh | bash # # OFFRIG_VERSION a release tag, such as v0.2.0 (default: the latest) # OFFRIG_PREFIX prefix where bin/offrig and libexec/offrigd-* go (default: ~/.local) # OFFRIG_BASE_URL where the archives are (default: the release's download URL; # CI points it at its own builds alongside OFFRIG_VERSION) set -euo pipefail repo="spiritledsoftware/offrig" version="${OFFRIG_VERSION:-latest}" prefix="${OFFRIG_PREFIX:-$HOME/.local}" bin_dir="$prefix/bin" libexec_dir="$prefix/libexec" say() { printf 'offrig install: %s\n' "$*" >&2; } die() { say "$*" exit 1 } case "$(uname -s)" in Darwin) os=apple-darwin ;; Linux) os=unknown-linux-musl ;; *) die "no release for $(uname -s); build it with cargo install --locked offrig" ;; esac case "$(uname -m)" in arm64 | aarch64) arch=aarch64 ;; x86_64 | amd64) arch=x86_64 ;; *) die "no release for $(uname -m); build it with cargo install --locked offrig" ;; esac target="$arch-$os" command -v curl >/dev/null || die "needs curl" command -v tar >/dev/null || die "needs tar" if command -v sha256sum >/dev/null; then sha256() { sha256sum "$1" | cut -d' ' -f1; } elif command -v shasum >/dev/null; then sha256() { shasum -a 256 "$1" | cut -d' ' -f1; } else die "needs sha256sum or shasum to check the download" fi if [ "$version" = latest ]; then [ -z "${OFFRIG_BASE_URL:-}" ] || die "OFFRIG_VERSION must be set when OFFRIG_BASE_URL is set" latest_url="$(curl -fsSLI -o /dev/null -w '%{url_effective}' "https://github.com/$repo/releases/latest")" || die "couldn't resolve latest release tag for $repo" version="${latest_url##*/}" case "$version" in v*) ;; *) die "couldn't resolve a release tag from $latest_url" ;; esac fi pkg="offrig-$version-$target" archive="$pkg.tar.gz" if [ -n "${OFFRIG_BASE_URL:-}" ]; then base="${OFFRIG_BASE_URL%/}" else base="https://github.com/$repo/releases/download/$version" fi tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT say "downloading $base/$archive" curl -fsSL --retry 3 -o "$tmp/$archive" "$base/$archive" || die "couldn't download $base/$archive" want="" if curl -fsSL --retry 3 -o "$tmp/$archive.sha256" "$base/$archive.sha256" 2>/dev/null; then want="$(awk '{ print $1 }' "$tmp/$archive.sha256" | head -n1)" elif curl -fsSL --retry 3 -o "$tmp/SHA256SUMS" "$base/SHA256SUMS" 2>/dev/null; then want="$(awk -v f="$archive" '$2 == f || $2 == ("*" f) || $2 == ("./" f) { print $1 }' "$tmp/SHA256SUMS" | head -n1)" else die "couldn't download checksum ($archive.sha256 or SHA256SUMS) from $base" fi [ -n "$want" ] || die "no sha256 entry for $archive" got="$(sha256 "$tmp/$archive")" [ "$want" = "$got" ] || die "$archive's checksum is $got, not $want" tar -xzf "$tmp/$archive" -C "$tmp" unpacked="$tmp/$pkg" [ -f "$unpacked/bin/offrig" ] || die "$archive has no bin/offrig in it" [ -f "$unpacked/libexec/offrigd-linux-x86_64" ] || die "$archive has no libexec/offrigd-linux-x86_64 in it" [ -f "$unpacked/libexec/offrigd-linux-aarch64" ] || die "$archive has no libexec/offrigd-linux-aarch64 in it" [ -f "$unpacked/libexec/offrigd.sha256" ] || die "$archive has no libexec/offrigd.sha256 in it" mkdir -p "$bin_dir" "$libexec_dir" # Copy to a fresh temp path beside each destination and rename over it: on macOS, # overwriting a signed binary in place makes the kernel kill it at launch. install_file() { local src="$1" dst="$2" mode="$3" local stage="$dst.new.$$" cp "$src" "$stage" chmod "$mode" "$stage" mv -f "$stage" "$dst" } # Stage sidecars before their manifest and the CLI binary so checksums stay consistent. install_file "$unpacked/libexec/offrigd-linux-x86_64" "$libexec_dir/offrigd-linux-x86_64" 0755 install_file "$unpacked/libexec/offrigd-linux-aarch64" "$libexec_dir/offrigd-linux-aarch64" 0755 install_file "$unpacked/libexec/offrigd.sha256" "$libexec_dir/offrigd.sha256" 0644 install_file "$unpacked/bin/offrig" "$bin_dir/offrig" 0755 installed="$("$bin_dir/offrig" --version)" || die "$bin_dir/offrig doesn't run" say "installed ${installed%%$'\n'*} into $prefix (bin/offrig + libexec/offrigd-*)" case ":$PATH:" in *":$bin_dir:"*) ;; *) say "$bin_dir isn't on your PATH; add it to use offrig" ;; esac say "run 'offrig doctor' to verify Rigs and bundled Linux offrigd sidecars" say "run 'offrig skill install' to install the bundled coding-agent skill (or connect 'offrig mcp')" say "a running Local daemon keeps the binary it started with: run 'offrig daemon stop' to pick up the new version" say "anonymous usage and crash telemetry can be inspected with 'offrig telemetry preview' or disabled anytime with 'offrig telemetry disable' or DO_NOT_TRACK=1"