#!/usr/bin/env bash # Install fld — FluidDocs CLI # # Recommended (public): # curl -fsSL https://fluiddocs.ai/install | bash # # Pin a versioned host (optional): # FLUIDDOCS_INSTALL_BASE=https://fluiddocs.ai bash -s < install.sh # # Override install directory: # curl -fsSL https://fluiddocs.ai/install | bash -s -- --dir ~/.local/bin set -euo pipefail INSTALL_BASE="${FLUIDDOCS_INSTALL_BASE:-https://fluiddocs.ai}" INSTALL_DIR="${FLUIDDOCS_CLI_INSTALL_DIR:-}" while [[ $# -gt 0 ]]; do case "$1" in --dir) INSTALL_DIR="${2:-}" if [[ -z "$INSTALL_DIR" ]]; then echo "Error: --dir requires a path" >&2 exit 1 fi shift 2 ;; --help|-h) echo "Install fld (FluidDocs CLI)" echo "" echo "Usage: install.sh [--dir DIR]" echo "" echo "Defaults:" echo " base \$FLUIDDOCS_INSTALL_BASE or https://fluiddocs.ai" echo " dir ~/.local/bin (or /usr/local/bin if writable)" exit 0 ;; *) echo "Unknown option: $1" >&2 exit 1 ;; esac done detect_asset() { local os arch os="$(uname -s | tr '[:upper:]' '[:lower:]')" arch="$(uname -m)" case "$os" in darwin) os="darwin" ;; linux) os="linux" ;; mingw*|msys*|cygwin*) os="windows" ;; *) echo "Error: unsupported OS: $(uname -s)" >&2 exit 1 ;; esac case "$arch" in x86_64|amd64) arch="x64" ;; arm64|aarch64) arch="arm64" ;; *) echo "Error: unsupported architecture: $arch" >&2 exit 1 ;; esac if [[ "$os" == "windows" ]]; then echo "fld-${os}-${arch}.exe" else echo "fld-${os}-${arch}" fi } resolve_install_dir() { if [[ -n "$INSTALL_DIR" ]]; then echo "$INSTALL_DIR" return fi if [[ -d /usr/local/bin && -w /usr/local/bin ]]; then echo "/usr/local/bin" return fi echo "${HOME}/.local/bin" } need_cmd() { if ! command -v "$1" >/dev/null 2>&1; then echo "Error: required command not found: $1" >&2 exit 1 fi } need_cmd curl need_cmd uname need_cmd mktemp # Trim trailing slash INSTALL_BASE="${INSTALL_BASE%/}" ASSET="$(detect_asset)" DEST_DIR="$(resolve_install_dir)" TMPDIR="$(mktemp -d)" trap 'rm -rf "$TMPDIR"' EXIT URL="${INSTALL_BASE}/install/${ASSET}" OUT="${TMPDIR}/${ASSET}" echo "Installing fld" echo " from: ${URL}" echo " into: ${DEST_DIR}/fld" if ! curl -fsSL "$URL" -o "$OUT"; then echo "Error: download failed from ${URL}" >&2 exit 1 fi # Reject accidental HTML error pages if head -c 15 "$OUT" | grep -qi '&2 exit 1 fi chmod +x "$OUT" mkdir -p "$DEST_DIR" if command -v install >/dev/null 2>&1; then install -m 755 "$OUT" "${DEST_DIR}/fld" else mv "$OUT" "${DEST_DIR}/fld" chmod 755 "${DEST_DIR}/fld" fi echo "" echo "Installed: ${DEST_DIR}/fld" if ! command -v fld >/dev/null 2>&1; then case ":${PATH}:" in *":${DEST_DIR}:"*) ;; *) echo "" echo "Add this to your PATH (e.g. in ~/.zshrc):" echo " export PATH=\"${DEST_DIR}:\$PATH\"" ;; esac fi echo "" echo "Try: fld --help" echo "Then: fld login"