claire/scripts/install.sh
2026-05-18 07:27:21 -07:00

52 lines
1.8 KiB
Bash
Executable file

#!/bin/sh
# install.sh — set up Clare locally.
#
# Two independent steps, each idempotent and runnable on its own:
#
# 1. venv + editable install via `uv` — requires `uv` on PATH.
# 2. Symlink the `clare` console script into ~/.local/bin — requires only
# that `.venv/bin/clare` already exists (built by step 1, or by an
# earlier run).
#
# Re-running the script always re-creates the symlink if the venv exists,
# even if `uv` is missing from the current PATH (the common partial-install
# case: venv was built in an interactive shell but the symlink step is
# being run from a non-interactive shell without uv on PATH).
set -eu
ROOT=$(cd "$(dirname "$0")/.." && pwd)
cd "$ROOT"
# ---------------------------------------------------------------------------
# Step 1: venv + editable install (skipped gracefully if uv is missing)
# ---------------------------------------------------------------------------
if command -v uv >/dev/null 2>&1; then
if [ ! -d "$ROOT/.venv" ]; then
uv venv
fi
uv pip install -e ".[dev]"
else
echo "install.sh: uv not on PATH; skipping venv build." >&2
echo " (will only succeed if .venv/bin/clare already exists)" >&2
fi
# ---------------------------------------------------------------------------
# Step 2: symlink — only depends on .venv/bin/clare existing
# ---------------------------------------------------------------------------
TARGET="$ROOT/.venv/bin/clare"
LINK="$HOME/.local/bin/clare"
if [ ! -x "$TARGET" ]; then
echo "install.sh: $TARGET does not exist; cannot create symlink." >&2
echo " install uv and re-run from an interactive shell, or run:" >&2
echo " cd $ROOT && uv venv && uv pip install -e ." >&2
exit 1
fi
mkdir -p "$HOME/.local/bin"
ln -sf "$TARGET" "$LINK"
echo "install.sh: linked $LINK -> $TARGET"
echo "install.sh: ensure ~/.local/bin is on your PATH"