#!/bin/sh # Installs the Underlay CLI from https://www.underlay.org: one JavaScript file, run by Node.js 22.6 or later. # Run it again to update. Read it first if you like: curl -fsSL https://www.underlay.org/cli/install.sh set -eu ORIGIN="https://www.underlay.org" DIR="${UNDERLAY_CLI_DIR:-$HOME/.local/share/underlay-cli}" BIN="${UNDERLAY_BIN_DIR:-$HOME/.local/bin}" say() { printf '%s\n' "$*"; } fail() { say "underlay: $*" >&2; exit 1; } command -v node >/dev/null 2>&1 || fail "the CLI runs on Node.js 22.6 or later, and node is not on your PATH. Get it from https://nodejs.org" node -e 'const [a, b] = process.versions.node.split(".").map(Number); process.exit(a > 22 || (a === 22 && b >= 6) ? 0 : 1)' \ || fail "the CLI needs Node.js 22.6 or later; this is $(node --version)" command -v curl >/dev/null 2>&1 || fail "curl is needed to download the CLI" mkdir -p "$DIR" "$BIN" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT say "Downloading the Underlay CLI from $ORIGIN" curl -fsSL "$ORIGIN/cli/underlay.js" -o "$TMP/underlay.js" || fail "could not download $ORIGIN/cli/underlay.js" curl -fsSL "$ORIGIN/cli/underlay.js.sha256" -o "$TMP/underlay.js.sha256" || fail "could not download its checksum" WANT="$(cut -d' ' -f1 < "$TMP/underlay.js.sha256")" if command -v shasum >/dev/null 2>&1; then HAVE="$(shasum -a 256 "$TMP/underlay.js" | cut -d' ' -f1)" else HAVE="$(sha256sum "$TMP/underlay.js" | cut -d' ' -f1)" fi [ "$WANT" = "$HAVE" ] || fail "the download does not match its checksum; nothing was installed" mv "$TMP/underlay.js" "$DIR/underlay.js" printf '%s\n' "$ORIGIN" > "$DIR/origin" cat > "$BIN/underlay" <> ~/.zshrc" ;; esac say "" say "Next:" say " underlay login underlay.org" say " underlay init" say " underlay" say "" say "Docs: $ORIGIN/docs/cli" say "Later, underlay update gets the newest build from here."