#!/bin/sh set -eu BASE_URL="${CHORUS_BASE_URL:-https://chorus.host}" INSTALL_DIR="${CHORUS_INSTALL_DIR:-/usr/local/bin}" TMP_DIR="$(mktemp -d)" cleanup() { rm -rf "$TMP_DIR" } trap cleanup EXIT INT TERM need() { if ! command -v "$1" >/dev/null 2>&1; then echo "install.sh: missing required command: $1" >&2 exit 1 fi } need curl need tar OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" case "$OS" in darwin) OS="darwin" ;; linux) OS="linux" ;; *) echo "install.sh: unsupported OS: $OS" >&2; exit 1 ;; esac case "$ARCH" in arm64|aarch64) ARCH="arm64" ;; x86_64|amd64) ARCH="amd64" ;; *) echo "install.sh: unsupported architecture: $ARCH" >&2; exit 1 ;; esac LATEST="$TMP_DIR/latest.json" curl -fsSL "$BASE_URL/downloads/beacon/latest.json" -o "$LATEST" VERSION="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$LATEST" | head -n 1)" if [ -z "$VERSION" ]; then echo "install.sh: could not read version from latest.json" >&2 exit 1 fi NAME="beacon-$OS-$ARCH.tar.gz" URL="$BASE_URL/downloads/beacon/$VERSION/$NAME" ARCHIVE="$TMP_DIR/$NAME" curl -fsSL "$URL" -o "$ARCHIVE" curl -fsSL "$BASE_URL/downloads/beacon/$VERSION/checksums.txt" -o "$TMP_DIR/checksums.txt" if command -v shasum >/dev/null 2>&1; then (cd "$TMP_DIR" && grep " $NAME\$" checksums.txt | shasum -a 256 -c -) elif command -v sha256sum >/dev/null 2>&1; then (cd "$TMP_DIR" && grep " $NAME\$" checksums.txt | sha256sum -c -) else echo "install.sh: warning: shasum/sha256sum not found; skipping checksum verification" >&2 fi tar -xzf "$ARCHIVE" -C "$TMP_DIR" chmod +x "$TMP_DIR/beacon" if [ ! -d "$INSTALL_DIR" ]; then mkdir -p "$INSTALL_DIR" 2>/dev/null || { echo "install.sh: cannot create $INSTALL_DIR; try CHORUS_INSTALL_DIR=\$HOME/.local/bin" >&2 exit 1 } fi if [ -w "$INSTALL_DIR" ]; then mv "$TMP_DIR/beacon" "$INSTALL_DIR/beacon" else sudo mv "$TMP_DIR/beacon" "$INSTALL_DIR/beacon" fi echo "Installed beacon $VERSION to $INSTALL_DIR/beacon"