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