#!/bin/sh # Bifrost installer for macOS. # # curl -fsSL https://impirios.com/bifrost/install.sh | sh # # What it does: # 1. works out your OS and chip # 2. downloads that build of bifrost from GitHub Releases # 3. checks its SHA-256 against the release's checksums.txt # 4. puts it in ~/.local/bin (no sudo) # # Options (environment variables): # BIFROST_VERSION=v0.6.1 install a specific version (default: latest) # BIFROST_INSTALL_DIR=/path install somewhere else (default: ~/.local/bin) # # Run it again any time to update. set -eu REPO="impirios/portals" main() { os=$(uname -s) # Releases are macOS-only for now. Linux and Windows build from source. case "$os" in Darwin) os=darwin ;; *) fail "Bifrost releases are macOS-only for now. On $os, build it from source (Go 1.22+): git clone https://github.com/impirios/portals && cd portals && go build -o bifrost ." ;; esac arch=$(uname -m) case "$arch" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "no build for this processor ($arch) yet" ;; esac # Apple Silicon Macs running this shell under Rosetta report x86_64; # give them the native build. if [ "$os" = darwin ] && [ "$arch" = amd64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = 1 ]; then arch=arm64 fi version="${BIFROST_VERSION:-latest}" if [ -n "${BIFROST_DOWNLOAD_BASE:-}" ]; then base="$BIFROST_DOWNLOAD_BASE" # for testing and mirrors elif [ "$version" = latest ]; then base="https://github.com/$REPO/releases/latest/download" else case "$version" in v*) ;; *) version="v$version" ;; esac base="https://github.com/$REPO/releases/download/$version" fi install_dir="${BIFROST_INSTALL_DIR:-$HOME/.local/bin}" archive="bifrost_${os}_${arch}.tar.gz" tmp=$(mktemp -d 2>/dev/null || mktemp -d -t bifrost) trap 'rm -rf "$tmp"' EXIT INT TERM say "Downloading bifrost ($version, $os/$arch)…" fetch "$base/$archive" "$tmp/$archive" fetch "$base/checksums.txt" "$tmp/checksums.txt" say "Checking its fingerprint…" want=$(awk -v f="$archive" '$2 == f { print $1 }' "$tmp/checksums.txt") [ -n "$want" ] || fail "checksums.txt has no entry for $archive" got=$(sha256 "$tmp/$archive") if [ "$want" != "$got" ]; then fail "the download doesn't match the release's checksum, so nothing was installed. expected $want got $got Try again; if it keeps happening, please report it." fi tar -xzf "$tmp/$archive" -C "$tmp" [ -f "$tmp/bifrost" ] || fail "the archive didn't contain bifrost" mkdir -p "$install_dir" # Write to a temp name, then rename: an already-running bifrost keeps working. cp "$tmp/bifrost" "$install_dir/.bifrost.new" chmod 755 "$install_dir/.bifrost.new" mv -f "$install_dir/.bifrost.new" "$install_dir/bifrost" installed=$("$install_dir/bifrost" version 2>/dev/null || echo "bifrost") say "" say "✓ Installed $installed → $install_dir/bifrost" # Is a different `bifrost` earlier in PATH? (Another tool uses the name.) other=$(command -v bifrost 2>/dev/null || true) if [ -n "$other" ] && [ "$other" != "$install_dir/bifrost" ]; then say "" say "Note: \`bifrost\` currently runs $other, a different program." say " Put $install_dir earlier in your PATH, or run $install_dir/bifrost directly." fi case ":$PATH:" in *":$install_dir:"*) ;; *) rc="$HOME/.profile" case "${SHELL:-}" in */zsh) rc="$HOME/.zshrc" ;; */bash) rc="$HOME/.bashrc" ;; */fish) rc="$HOME/.config/fish/config.fish" ;; esac say "" say "Add it to your PATH (once), then open a new terminal:" case "$rc" in *.fish) say " echo 'fish_add_path $install_dir' >> $rc" ;; *) say " echo 'export PATH=\"$install_dir:\$PATH\"' >> $rc" ;; esac ;; esac say "" say "Get started:" say " bifrost pair on your first device: shows a 6-digit code" say " bifrost pair 123456 on the next one, with that code" say " bifrost ui send and receive" } fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL --proto '=https,http' --retry 2 -o "$2" "$1" || fail "couldn't download $1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" || fail "couldn't download $1" else fail "needs curl or wget" fi } sha256() { if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | awk '{ print $1 }' elif command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{ print $1 }' else fail "needs shasum or sha256sum to verify the download" fi } say() { printf '%s\n' "$1"; } fail() { printf 'bifrost install: %s\n' "$1" >&2 exit 1 } # Everything runs from here, so a download cut off halfway through # (curl | sh) can't run a partial script. main "$@"