#!/usr/bin/env bash set -euo pipefail repo=nodepile/camp bin="$HOME/.local/bin" if [[ "$(uname -s)" != "Linux" ]]; then echo "camp runs on Ubuntu and Debian only" >&2 exit 1 fi if ! command -v gh >/dev/null; then echo "camp is downloaded with the GitHub CLI, which is missing; installing it (needs sudo)" sudo apt-get update &1 | sed -n 's/.*account \([^ ]*\).*/\1/p' } if [[ -z "$(accounts)" ]]; then echo "log in with the GitHub account that has access to $repo" gh auth login --hostname github.com --web --git-protocol https /dev/null) || continue if GH_TOKEN="$token" gh release download --repo "$repo" --pattern "$asset" --pattern checksums.txt --dir "$tmp" --clobber 2>/dev/null; then used="$login" return 0 fi done return 1 } used="" if ! fetch; then echo "none of your GitHub accounts ($(accounts | paste -sd, -)) can read $repo; log in with the one that can" gh auth login --hostname github.com --web --git-protocol https &2 exit 1 fi fi (cd "$tmp" && sha256sum --check --ignore-missing --quiet checksums.txt) tar -xzf "$tmp/$asset" -C "$tmp" camp install -D -m 755 "$tmp/camp" "$bin/camp" echo "camp $("$bin/camp" --version | awk '{print $NF}') installed to $bin/camp using the GitHub account $used" case ":$PATH:" in *":$bin:"*) echo "next: camp" ;; *) echo "next: add $bin to your PATH (log out and back in usually does it), then run camp" ;; esac