install.sh93 lines · main
| 1 | #!/usr/bin/env sh |
| 2 | # briven CLI installer — pulls the tarball published as a Codeberg release |
| 3 | # asset and drops a `briven` shim into the user's PATH. |
| 4 | # |
| 5 | # Usage: |
| 6 | # curl -fsSL https://briven.tech/install | sh |
| 7 | # curl -fsSL https://briven.tech/install | BRIVEN_CLI_VERSION=0.2.0 sh |
| 8 | # curl -fsSL https://briven.tech/install | BRIVEN_CLI_PREFIX="$HOME/.local" sh |
| 9 | # |
| 10 | # Requires: curl OR wget; tar; a node runtime (node >=20 OR bun) on PATH. |
| 11 | |
| 12 | set -eu |
| 13 | |
| 14 | VERSION="${BRIVEN_CLI_VERSION:-0.2.0}" |
| 15 | PREFIX="${BRIVEN_CLI_PREFIX:-$HOME/.local}" |
| 16 | RELEASE_HOST="${BRIVEN_RELEASE_HOST:-https://codeberg.org}" |
| 17 | RELEASE_REPO="${BRIVEN_RELEASE_REPO:-flndrn/briven}" |
| 18 | TARBALL_NAME="briven-cli-${VERSION}.tgz" |
| 19 | TARBALL_URL="${RELEASE_HOST}/${RELEASE_REPO}/releases/download/cli-v${VERSION}/${TARBALL_NAME}" |
| 20 | INSTALL_DIR="${PREFIX}/share/briven-cli" |
| 21 | BIN_DIR="${PREFIX}/bin" |
| 22 | SHIM="${BIN_DIR}/briven" |
| 23 | |
| 24 | step() { printf '\033[1;36m▸\033[0m %s\n' "$1"; } |
| 25 | warn() { printf '\033[1;33m!\033[0m %s\n' "$1" >&2; } |
| 26 | fail() { printf '\033[1;31m✗\033[0m %s\n' "$1" >&2; exit 1; } |
| 27 | |
| 28 | # ─── Preflight ────────────────────────────────────────────────────────────── |
| 29 | |
| 30 | have_runtime=0 |
| 31 | if command -v node >/dev/null 2>&1; then |
| 32 | have_runtime=1 |
| 33 | elif command -v bun >/dev/null 2>&1; then |
| 34 | have_runtime=1 |
| 35 | fi |
| 36 | if [ "$have_runtime" -eq 0 ]; then |
| 37 | fail "node (>=20) or bun is required on PATH. Install one first, then re-run." |
| 38 | fi |
| 39 | |
| 40 | if ! command -v tar >/dev/null 2>&1; then |
| 41 | fail "tar is required." |
| 42 | fi |
| 43 | |
| 44 | fetcher="" |
| 45 | if command -v curl >/dev/null 2>&1; then |
| 46 | fetcher="curl -fsSL" |
| 47 | elif command -v wget >/dev/null 2>&1; then |
| 48 | fetcher="wget -qO-" |
| 49 | else |
| 50 | fail "curl or wget required." |
| 51 | fi |
| 52 | |
| 53 | # ─── Download ─────────────────────────────────────────────────────────────── |
| 54 | |
| 55 | tmp="$(mktemp -d)" |
| 56 | trap 'rm -rf "$tmp"' EXIT |
| 57 | |
| 58 | step "Downloading ${TARBALL_NAME} from Codeberg release cli-v${VERSION}" |
| 59 | if ! $fetcher "$TARBALL_URL" > "$tmp/$TARBALL_NAME"; then |
| 60 | fail "download failed: $TARBALL_URL" |
| 61 | fi |
| 62 | |
| 63 | # Codeberg returns HTML on 404 — confirm we got a real tarball. |
| 64 | if ! tar -tzf "$tmp/$TARBALL_NAME" >/dev/null 2>&1; then |
| 65 | fail "downloaded file is not a tarball — version cli-v${VERSION} may not have a release asset yet" |
| 66 | fi |
| 67 | |
| 68 | # ─── Install ──────────────────────────────────────────────────────────────── |
| 69 | |
| 70 | mkdir -p "$INSTALL_DIR" "$BIN_DIR" |
| 71 | |
| 72 | step "Extracting to $INSTALL_DIR" |
| 73 | # npm-pack tarballs unpack as ./package/* — strip that prefix. |
| 74 | tar -xzf "$tmp/$TARBALL_NAME" -C "$INSTALL_DIR" --strip-components=1 |
| 75 | |
| 76 | step "Writing shim to $SHIM" |
| 77 | cat > "$SHIM" <<EOF |
| 78 | #!/usr/bin/env sh |
| 79 | # briven CLI shim — generated by installer |
| 80 | exec node "$INSTALL_DIR/bin/briven.js" "\$@" |
| 81 | EOF |
| 82 | chmod +x "$SHIM" |
| 83 | |
| 84 | # ─── PATH check ───────────────────────────────────────────────────────────── |
| 85 | |
| 86 | if ! echo ":$PATH:" | grep -q ":$BIN_DIR:"; then |
| 87 | warn "$BIN_DIR is not on your PATH." |
| 88 | warn "Add it to ~/.zshrc or ~/.bashrc:" |
| 89 | warn " export PATH=\"$BIN_DIR:\$PATH\"" |
| 90 | fi |
| 91 | |
| 92 | printf '\n\033[1;32m✓\033[0m briven %s installed.\n' "$VERSION" |
| 93 | printf ' Run: \033[1mbriven\033[0m\n\n' |