#!/bin/sh
# blip CLI installer, served at https://blip.zone/cli/install.sh
# Downloads the binary for this OS/arch from the same origin, checks it against SHA256SUMS, installs to $BLIP_BIN_DIR (default ~/.local/bin).
set -eu
BASE=${BLIP_CLI_BASE:-https://blip.zone/cli}
DIR=${BLIP_BIN_DIR:-$HOME/.local/bin}
case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) echo "blip: unsupported OS $(uname -s); download a binary from $BASE/ by hand" >&2; exit 1 ;; esac
case "$(uname -m)" in x86_64|amd64) arch=amd64 ;; arm64|aarch64) arch=arm64 ;; *) echo "blip: unsupported arch $(uname -m)" >&2; exit 1 ;; esac
f=blip-$os-$arch
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
curl -fsSL "$BASE/$f" -o "$tmp/$f"
curl -fsSL "$BASE/SHA256SUMS" -o "$tmp/SHA256SUMS"
want=$(grep " $f\$" "$tmp/SHA256SUMS" | cut -d' ' -f1)
if command -v sha256sum >/dev/null 2>&1; then got=$(sha256sum "$tmp/$f" | cut -d' ' -f1); else got=$(shasum -a 256 "$tmp/$f" | cut -d' ' -f1); fi
[ -n "$want" ] && [ "$want" = "$got" ] || { echo "blip: checksum mismatch for $f" >&2; exit 1; }
mkdir -p "$DIR" && install -m 0755 "$tmp/$f" "$DIR/blip"
echo "blip installed to $DIR/blip ($("$DIR/blip" version 2>/dev/null || echo ok))"
case ":$PATH:" in *":$DIR:"*) ;; *) echo "Add $DIR to your PATH." ;; esac
