76 lines
2.7 KiB
Bash
Executable File
76 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# shellbound installer -- checks prerequisites, installs the CLI, and verifies.
|
|
# Usage: bash install.sh
|
|
set -euo pipefail
|
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
say() { printf 'install: %s\n' "$*"; }
|
|
die() { printf 'install: ERROR: %s\n' "$*" >&2; exit 1; }
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Prerequisites
|
|
# ---------------------------------------------------------------------------
|
|
command -v python3 >/dev/null 2>&1 || die "python3 is required but not on PATH"
|
|
if ! python3 - <<'PY'
|
|
import sys
|
|
sys.exit(0 if sys.version_info >= (3, 10) else 1)
|
|
PY
|
|
then
|
|
die "python3 >= 3.10 is required (found: $(python3 --version 2>&1))"
|
|
fi
|
|
say "python3 OK ($(python3 --version 2>&1))"
|
|
|
|
if ! python3 -m pip --version >/dev/null 2>&1; then
|
|
die "pip is required but 'python3 -m pip' fails; install pip first"
|
|
fi
|
|
say "pip OK"
|
|
|
|
CLIP=""
|
|
for t in xclip wl-copy pbcopy xsel; do
|
|
if command -v "$t" >/dev/null 2>&1; then CLIP="$t"; break; fi
|
|
done
|
|
if [ -z "$CLIP" ]; then
|
|
say "note: no clipboard backend found (xclip/wl-copy/pbcopy/xsel);"
|
|
say " --copy/--paste will be unavailable until one is installed."
|
|
fi
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Install
|
|
# ---------------------------------------------------------------------------
|
|
say "installing from $DIR ..."
|
|
if [ -n "${VIRTUAL_ENV:-}" ]; then
|
|
python3 -m pip install "$DIR"
|
|
else
|
|
say "installing to the user site-packages ..."
|
|
if ! python3 -m pip install --user "$DIR"; then
|
|
say "user-site install failed; retrying with --break-system-packages (PEP 668) ..."
|
|
python3 -m pip install --user --break-system-packages "$DIR" \
|
|
|| die "pip install failed (see output above)"
|
|
fi
|
|
fi
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Verify
|
|
# ---------------------------------------------------------------------------
|
|
say "verifying install ..."
|
|
python3 -m shellbound --version >/dev/null 2>&1 \
|
|
|| die "installed but 'python3 -m shellbound --version' failed"
|
|
|
|
BINDIR=""
|
|
if [ -d "${VIRTUAL_ENV:-}" ] && [ -x "$VIRTUAL_ENV/bin/shellbound" ]; then
|
|
BINDIR="$VIRTUAL_ENV/bin"
|
|
elif [ -x "$HOME/.local/bin/shellbound" ]; then
|
|
BINDIR="$HOME/.local/bin"
|
|
fi
|
|
|
|
if [ -n "$BINDIR" ]; then
|
|
if ! "$BINDIR/shellbound" --version >/dev/null 2>&1; then
|
|
say "note: the 'shellbound' command is at $BINDIR but is not on PATH;"
|
|
say " add it with: export PATH=\"$BINDIR:\$PATH\""
|
|
fi
|
|
else
|
|
say "note: the 'shellbound' console script may not be on PATH; try:"
|
|
say " export PATH=\"$HOME/.local/bin:\$PATH\""
|
|
fi
|
|
|
|
say "done. Next: run 'shellbound setup' to configure the gateway and API key." |