#!/bin/sh # Installs the heaven program on macOS or Linux: # # curl -fsSL https://heaven.dev/install | sh # # It downloads the program for this computer from https://heaven.dev/cli, # checks it against the SHA256SUMS published beside it, and puts it in # ~/.local/bin (HEAVEN_INSTALL_DIR). Running it again updates the program; a # download that fails its check leaves the installed one as it was. # deploy/cli/build.sh fills in the domain. set -eu base="${HEAVEN_DOWNLOADS:-https://heaven.dev/cli}" dir="${HEAVEN_INSTALL_DIR:-$HOME/.local/bin}" fail() { echo "heaven install: $*" >&2; exit 1; } case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) fail "this computer runs $(uname -s); the heaven program is built for macOS and Linux" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "the heaven program is not built for $(uname -m) processors" ;; esac name="heaven-$os-$arch" command -v ssh >/dev/null 2>&1 || fail "the heaven program uses OpenSSH; install it (ssh) first" if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL -o "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q -O "$2" "$1"; } else fail "curl or wget is required" fi if command -v sha256sum >/dev/null 2>&1; then sum() { sha256sum "$1" | cut -d' ' -f1; } elif command -v shasum >/dev/null 2>&1; then sum() { shasum -a 256 "$1" | cut -d' ' -f1; } else fail "sha256sum or shasum is required" fi tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT fetch "$base/SHA256SUMS" "$tmp/SHA256SUMS" || fail "could not download $base/SHA256SUMS" fetch "$base/$name" "$tmp/heaven" || fail "could not download $base/$name" want="$(awk -v n="$name" '$2 == n { print $1 }' "$tmp/SHA256SUMS")" [ -n "$want" ] || fail "$name is not published" [ "$(sum "$tmp/heaven")" = "$want" ] || fail "$name does not match its published checksum; nothing was installed" chmod 755 "$tmp/heaven" mkdir -p "$dir" # A rename within the directory: a heaven already running keeps its file. cp "$tmp/heaven" "$dir/.heaven.$$" mv -f "$dir/.heaven.$$" "$dir/heaven" echo "Installed $("$dir/heaven" version) at $dir/heaven" case "${SHELL:-}" in */zsh) profile="~/.zshrc" ;; */bash) profile="~/.bashrc" ;; *) profile="~/.profile" ;; esac case ":$PATH:" in *":$dir:"*) ;; *) echo "Add $dir to your PATH: echo 'export PATH=\"$dir:\$PATH\"' >> $profile" ;; esac echo "Next, run: heaven login"