llm-host/install.sh
neil b07af69afa Installer: add ~/.local/bin to PATH instead of only warning
Appends an export to the profile for the user's shell (zsh: .zshrc,
bash: .bash_profile on macOS / .bashrc on Linux, fish: config.fish),
once, and tells the user to open a new terminal at the end of setup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QaE1hpvyZTJixEbUUMj9Ca
2026-11-02 05:44:35 -08:00

117 lines
4.6 KiB
Bash
Executable file

#!/bin/bash
# llm-host installer.
#
# /bin/bash -c "$(curl -fsSL https://git.neilbantoc.dev/pub/llm-host/raw/branch/main/install.sh)"
#
# Pass setup options after `--`, e.g. ... install.sh)" -- --default ornith-1.5-35b --yes
# Environment overrides: LLMHOST_REPO, LLMHOST_REF, LLMHOST_HOME.
#
# Installs only into your home directory (no sudo): uv, a private Python, this repo,
# the inference backend (vLLM on Linux+NVIDIA, MLX on Apple Silicon) and user services.
# Written for bash 3.2 so it runs on stock macOS.
set -euo pipefail
REPO="${LLMHOST_REPO:-https://git.neilbantoc.dev/pub/llm-host.git}"
REF="${LLMHOST_REF:-main}"
DATA="${LLMHOST_HOME:-$HOME/.local/share/llm-host}"
SRC="$DATA/src"
BIN="$HOME/.local/bin"
if [ -t 1 ]; then B=$'\033[1m'; R=$'\033[31m'; Y=$'\033[33m'; G=$'\033[32m'; N=$'\033[0m'; else B=""; R=""; Y=""; G=""; N=""; fi
say() { printf '%s==>%s %s\n' "$B" "$N" "$*"; }
warn() { printf '%sWarning:%s %s\n' "$Y" "$N" "$*" >&2; }
die() { printf '%sError:%s %s\n' "$R" "$N" "$*" >&2; exit 1; }
[ "${1:-}" = "--" ] && shift
# ---- platform checks: fail early with a useful message ----
OS="$(uname -s)"; ARCH="$(uname -m)"
case "$OS" in
Darwin)
[ "$ARCH" = "arm64" ] || die "llm-host needs Apple Silicon on macOS (MLX doesn't run on Intel Macs)."
if ! xcode-select -p >/dev/null 2>&1; then
die "Xcode Command Line Tools are needed for git. Run: xcode-select --install then re-run this installer."
fi
;;
Linux)
if ! command -v nvidia-smi >/dev/null 2>&1; then
die "No NVIDIA driver found (nvidia-smi is missing). llm-host on Linux needs an NVIDIA GPU with its driver installed."
fi
if ! nvidia-smi -L >/dev/null 2>&1; then
die "nvidia-smi can't talk to the NVIDIA driver. Fix the driver (a reboot after driver updates often helps), then re-run."
fi
if ! command -v cc >/dev/null 2>&1 && ! command -v gcc >/dev/null 2>&1; then
die "No C compiler found; vLLM's Triton kernels need one. Debian/Ubuntu/Pop!_OS: sudo apt install build-essential"
fi
;;
*) die "Unsupported OS: $OS (llm-host supports Linux with NVIDIA, and macOS on Apple Silicon)." ;;
esac
for tool in curl git; do
command -v "$tool" >/dev/null 2>&1 || die "$tool is required but not installed."
done
mkdir -p "$BIN" "$DATA"
# ---- uv (Python + package manager), installed per-user ----
UV="$(command -v uv 2>/dev/null || true)"
[ -z "$UV" ] && [ -x "$BIN/uv" ] && UV="$BIN/uv"
if [ -z "$UV" ]; then
say "Installing uv"
curl -LsSf https://astral.sh/uv/install.sh | env UV_NO_MODIFY_PATH=1 UV_INSTALL_DIR="$BIN" sh >/dev/null
UV="$BIN/uv"
fi
[ -x "$UV" ] || die "uv install failed"
# ---- llm-host itself ----
if [ -d "$SRC/.git" ]; then
say "Updating llm-host in $SRC"
git -C "$SRC" fetch --quiet --depth 1 origin "$REF"
git -C "$SRC" reset --quiet --hard FETCH_HEAD
else
say "Downloading llm-host to $SRC"
rm -rf "$SRC"
git clone --quiet --depth 1 --branch "$REF" "$REPO" "$SRC"
fi
# ---- a private Python for llm-host (stdlib only, no venv needed) ----
say "Setting up Python"
"$UV" python install 3.12 >/dev/null 2>&1 || die "couldn't install Python 3.12 with uv"
PY="$("$UV" python find --managed-python 3.12)"
[ -x "$PY" ] || die "couldn't locate the uv-managed Python"
cat > "$BIN/llmhost" <<EOF
#!/bin/sh
# llm-host launcher (generated by install.sh)
PYTHONPATH="$SRC" exec "$PY" -P -m llmhost "\$@"
EOF
chmod +x "$BIN/llmhost"
# Put ~/.local/bin on PATH for future shells (like uv's and opencode's installers do).
add_to_path() {
case ":$PATH:" in *":$BIN:"*) return 0 ;; esac
local rc line
case "$(basename "${SHELL:-}")" in
zsh) rc="${ZDOTDIR:-$HOME}/.zshrc"; line='export PATH="$HOME/.local/bin:$PATH"' ;;
bash) if [ "$OS" = "Darwin" ]; then rc="$HOME/.bash_profile"; else rc="$HOME/.bashrc"; fi
line='export PATH="$HOME/.local/bin:$PATH"' ;;
fish) rc="$HOME/.config/fish/config.fish"; line='fish_add_path $HOME/.local/bin' ;;
*) warn "$BIN isn't on your PATH. Add it in your shell's startup file: export PATH=\"$BIN:\$PATH\""; return 0 ;;
esac
if grep -qsF '$HOME/.local/bin' "$rc" || grep -qsF "$BIN" "$rc"; then
PATH_NOTE="$rc" # already configured; only this shell is missing it
return 0
fi
mkdir -p "$(dirname "$rc")"
printf '\n# Added by llm-host\n%s\n' "$line" >> "$rc"
say "Added $BIN to your PATH in $rc"
PATH_NOTE="$rc"
}
PATH_NOTE=""
add_to_path
if [ -n "$PATH_NOTE" ]; then
# Shown before setup's long output so it isn't missed; setup repeats it at the end.
export LLMHOST_PATH_NOTE="Open a new terminal (or run: source $PATH_NOTE) to use the llmhost command."
fi
say "Running setup"
exec "$BIN/llmhost" setup "$@"