#!/bin/sh # Installs the Buraq command line tool on Linux or macOS. # # curl -fsSL https://staging.buraq.fly/install.sh | sh # # It downloads the build for this computer, checks it against SHA256SUMS, checks that list's # signature with the key below, and only then puts `buraq` in ~/.local/bin. Nothing runs as root. # Read it first if you like; it is short. # # BURAQ_INSTALL_DIR where to put it (default ~/.local/bin) set -eu api='https://staging-api.buraq.fly' key='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB7Whyoic/hv40YxvsiTFth27XsVkVy5E8FVBCmHCL5G' dir=${BURAQ_INSTALL_DIR:-"$HOME/.local/bin"} say() { printf ' %s\n' "$*" >&2; } fail() { printf '\n Buraq was not installed: %s\n\n' "$*" >&2; exit 1; } case "$(uname -s)" in Linux) os=linux ;; Darwin) os=macos ;; *) fail "this script is for Linux and macOS. On Windows, see https://staging.buraq.fly/download/" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=x86_64 ;; aarch64 | arm64) arch=aarch64 ;; *) fail "there is no build for $(uname -m) yet." ;; esac # One macOS build runs on Apple silicon and Intel alike. if [ "$os" = macos ]; then platform=macos-universal; else platform=$os-$arch; fi if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL --proto '=https' --tlsv1.2 -o "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q --https-only -O "$2" "$1"; } else fail "it needs curl or wget." fi if command -v sha256sum >/dev/null 2>&1; then digest() { sha256sum "$1" | cut -d' ' -f1; } elif command -v shasum >/dev/null 2>&1; then digest() { shasum -a 256 "$1" | cut -d' ' -f1; } else fail "it needs sha256sum or shasum to check the download." fi work=$(mktemp -d) trap 'rm -rf "$work"' EXIT INT TERM cd "$work" say "Downloading Buraq for $platform" fetch "$api/v1/downloads/cli/SHA256SUMS" SHA256SUMS || fail "the release list could not be downloaded." fetch "$api/v1/downloads/cli/SHA256SUMS.sig" SHA256SUMS.sig || fail "the release signature could not be downloaded." # The signature proves the list came from Buraq, even if the server that sent it did not. command -v ssh-keygen >/dev/null 2>&1 || fail "Install OpenSSH 8.1 or later to verify the release signature." printf 'buraq namespaces="buraq-release" %s\n' "$key" >allowed_signers ssh-keygen -Y verify -f allowed_signers -I buraq -n buraq-release -s SHA256SUMS.sig -, which the signature covers. file=$(awk -v p="$platform" '$2 ~ ("^buraq-(.+-)?" p "\\.(tar\\.gz|zip)$") { print $2 }' SHA256SUMS) want=$(awk -v p="$platform" '$2 ~ ("^buraq-(.+-)?" p "\\.(tar\\.gz|zip)$") { print $1 }' SHA256SUMS) [ -n "$file" ] || fail "this release has no build for $platform." fetch "$api/v1/downloads/cli/$platform" "$file" || fail "the download failed." [ "$(digest "$file")" = "$want" ] || fail "the download does not match its checksum. Nothing was changed." say "Checksum matches" tar -xzf "$file" buraq mkdir -p "$dir" # Replace in one step, so a running copy is never half written. mv -f buraq "$dir/buraq.new" chmod 755 "$dir/buraq.new" mv -f "$dir/buraq.new" "$dir/buraq" say "Installed $("$dir/buraq" --version) in $dir" case ":$PATH:" in *":$dir:"*) say "Run: buraq" ;; *) case "${SHELL:-}" in */fish) say "Add it to your PATH: fish_add_path $dir" ;; */zsh) say "Add it to your PATH: echo 'export PATH=\"$dir:\$PATH\"' >> ~/.zshrc" ;; *) say "Add it to your PATH: echo 'export PATH=\"$dir:\$PATH\"' >> ~/.profile" ;; esac ;; esac