#!/bin/sh # Install poke, the Repoke CLI. # curl -fsSL https://repoke.app/install.sh | sh # Env: POKE_INSTALL_DIR (default $HOME/.local/bin), POKE_BASE_URL (default https://repoke.app/releases/latest) set -eu BASE_URL="${POKE_BASE_URL:-https://repoke.app/releases/latest}" INSTALL_DIR="${POKE_INSTALL_DIR:-$HOME/.local/bin}" say() { printf '%s\n' "$*"; } fail() { printf 'install.sh: %s\n' "$*" >&2; exit 1; } have() { command -v "$1" >/dev/null 2>&1; } case "$(uname -s)" in Darwin) os=apple-darwin ;; Linux) os=unknown-linux-musl ;; *) fail "unsupported OS: $(uname -s) (poke supports macOS and Linux)" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=x86_64 ;; arm64 | aarch64) arch=aarch64 ;; *) fail "unsupported CPU: $(uname -m) (poke supports x86_64 and aarch64)" ;; esac target="$arch-$os" archive="poke-$target.tar.gz" if have curl; then fetch() { curl -fsSL --proto '=https' --tlsv1.2 -o "$2" "$1"; } elif have wget; then fetch() { wget -q --https-only -O "$2" "$1"; } else fail "curl or wget is required" fi if have sha256sum; then sha256() { sha256sum "$1" | awk '{print $1}'; } elif have shasum; then sha256() { shasum -a 256 "$1" | awk '{print $1}'; } else fail "sha256sum or shasum is required to verify the download" fi tmp="$(mktemp -d 2>/dev/null || mktemp -d -t poke)" trap 'rm -rf "$tmp"' EXIT INT TERM say "Downloading $archive" fetch "$BASE_URL/$archive" "$tmp/$archive" || fail "download failed: $BASE_URL/$archive" fetch "$BASE_URL/$archive.sha256" "$tmp/$archive.sha256" || fail "download failed: $BASE_URL/$archive.sha256" # The .sha256 file holds the hex digest, optionally followed by the file name. expected="$(awk 'NR==1 {print $1}' "$tmp/$archive.sha256" | tr 'A-F' 'a-f')" actual="$(sha256 "$tmp/$archive")" [ -n "$expected" ] || fail "empty checksum file" [ "$expected" = "$actual" ] || fail "checksum mismatch for $archive (expected $expected, got $actual)" say "Checksum OK" tar -xzf "$tmp/$archive" -C "$tmp" bin="$tmp/poke" [ -f "$bin" ] || bin="$(find "$tmp" -type f -name poke | head -n 1)" [ -n "$bin" ] && [ -f "$bin" ] || fail "poke binary not found in $archive" mkdir -p "$INSTALL_DIR" chmod 0755 "$bin" mv -f "$bin" "$INSTALL_DIR/poke" say "Installed poke to $INSTALL_DIR/poke" case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) say "" say "$INSTALL_DIR is not on your PATH. Add this line to your shell profile:" say " export PATH=\"$INSTALL_DIR:\$PATH\"" ;; esac say "" say "Next: sign in this machine" say " poke auth login"