#!/usr/bin/env bash # # install.sh -- Install all dependencies for llm-d-benchmark # # Can be run two ways: # # 1. From inside the repo: # ./install.sh # # 2. Via curl (auto-clones the repo into ./llm-d-benchmark): # curl -sSL https://raw.githubusercontent.com/llm-d/llm-d-benchmark/main/install.sh | bash # # To clone a specific branch: # curl -sSL ... | LLMDBENCH_BRANCH=my-branch bash # # Installs the llmdbenchmark CLI, planner, and validates # that required system tools are available. # # Usage: # ./install.sh # interactive -- prompts for uv choice # ./install.sh --uv # use uv for venv creation (no prompt) # ./install.sh --no-uv # use python3 -m venv (no prompt) # ./install.sh -y # non-interactive -- allows system python # ./install.sh noreset # skip cache reset (re-use previous checks) # source install.sh # also works when sourced # set -euo pipefail REPO_URL="https://github.com/llm-d/llm-d-benchmark.git" REPO_DIR="llm-d-benchmark" DEFAULT_BRANCH="main" export _APT_GET_UPDATE_RUN=0 # --------------------------------------------------------------------------- # pip isolation # Any pip.conf on the machine (e.g. a corporate index that injects credentials # or redirects to an internal mirror) will break: # - editable local installs (index doesn't know about local paths) # - git+https:// installs (index can't proxy GitHub source URLs) # # We force every pip call in this script to run with: # PIP_CONFIG_FILE=/dev/null -- ignores all pip.conf files # --isolated -- disables env-var overrides too # # PyPI is still reachable; we are only suppressing *custom* index injection. # If your environment truly requires a proxy, set LLMDBENCH_PIP_EXTRA_ARGS # before running, e.g.: # export LLMDBENCH_PIP_EXTRA_ARGS="--index-url https://my.mirror/simple" # --------------------------------------------------------------------------- LLMDBENCH_PIP_EXTRA_ARGS="${LLMDBENCH_PIP_EXTRA_ARGS:-}" _pip_isolated() { PIP_CONFIG_FILE=/dev/null ${PIP_CMD} --isolated "$@" ${LLMDBENCH_PIP_EXTRA_ARGS} } # --------------------------------------------------------------------------- # Architecture detection # Normalises uname -m output into two variables used throughout: # ARCH_UNAME -- raw uname -m value (x86_64 | aarch64 | armv7l | ...) # ARCH_GO -- Go-style name (amd64 | arm64 | arm | ...) # ARCH_DEB -- Debian/apt name (amd64 | arm64 | armhf | ...) # --------------------------------------------------------------------------- ARCH_UNAME="$(uname -m)" case "$ARCH_UNAME" in x86_64) ARCH_GO="amd64"; ARCH_DEB="amd64" ;; aarch64|arm64) ARCH_GO="arm64"; ARCH_DEB="arm64" ;; armv7l|armhf) ARCH_GO="arm"; ARCH_DEB="armhf" ;; ppc64le) ARCH_GO="ppc64le"; ARCH_DEB="ppc64el" ;; s390x) ARCH_GO="s390x"; ARCH_DEB="s390x" ;; *) echo "WARNING: Unrecognised architecture '${ARCH_UNAME}'. Assuming amd64." ARCH_GO="amd64"; ARCH_DEB="amd64" ;; esac tool_version_for() { case "$1" in curl) echo "8_21_0" ;; helmfile) echo "1.5.1" ;; helm) echo "v3.19.0" ;; helm-diff) echo "v3.13.0" ;; # helm-diff build compatible with Helm 4's plugin SDK; selected at # install time when an on-PATH helm is already major version 4+. helm-diff-v4) echo "v3.15.7" ;; oc) echo "4.18.0" ;; *) echo "" ;; esac } # --------------------------------------------------------------------------- # Bootstrap: if run via curl (no repo present), clone first # curl -sSL https://raw.githubusercontent.com/llm-d/llm-d-benchmark/main/install.sh | bash # --------------------------------------------------------------------------- _bootstrap_if_needed() { local need_clone=false if [[ -z "${BASH_SOURCE[0]:-}" || "${BASH_SOURCE[0]}" == "bash" || "${BASH_SOURCE[0]}" == "/dev/stdin" ]]; then need_clone=true elif [[ ! -f "pyproject.toml" && ! -d "llmdbenchmark" ]]; then need_clone=true fi if [[ "$need_clone" == "true" ]]; then echo "" echo " llm-d-benchmark repository not detected in current directory." echo "" if [[ -d "${REPO_DIR}" && -f "${REPO_DIR}/pyproject.toml" ]]; then echo " Found existing clone at ./${REPO_DIR}" cd "${REPO_DIR}" else if ! command -v git &>/dev/null; then echo " ERROR: git is required but not installed." exit 1 fi local branch="${LLMDBENCH_BRANCH:-${DEFAULT_BRANCH}}" echo " Cloning ${REPO_URL} (branch: ${branch})..." git clone --branch "${branch}" "${REPO_URL}" "${REPO_DIR}" cd "${REPO_DIR}" echo " Cloned to $(pwd)" fi echo "" exec bash install.sh "$@" fi } _bootstrap_if_needed "$@" # --------------------------------------------------------------------------- # Resolve script directory (works whether sourced or executed) # --------------------------------------------------------------------------- if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" else SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" fi # --------------------------------------------------------------------------- # Help screen # --------------------------------------------------------------------------- show_help() { cat <<'HELP' install.sh — Install all dependencies for llm-d-benchmark USAGE ./install.sh [OPTIONS] source install.sh [OPTIONS] DESCRIPTION Sets up the complete development / runtime environment for llm-d-benchmark. 1. Validates Python 3.14+ and pip 2. Checks for required system tools (curl, git, kubectl, helm, helmfile) 3. Checks optional system tools (oc) 4. Installs llmdbenchmark (editable: pip install -e .) 5. Installs planner (llm-d-planner) (pip install git+https://...) 6. Verifies that all Python packages are importable Supported architectures: x86_64 (amd64), aarch64/arm64, armv7l, ppc64le, s390x. If no virtual environment is active, the script will automatically create one at .venv/ and activate it for the install. You will be prompted whether to use uv (https://docs.astral.sh/uv/) or the standard python3 -m venv. uv can automatically download the correct Python version if your system Python is missing or older than 3.14. Use --uv or --no-uv to skip the prompt. When run non-interactively (e.g. curl pipe), the script auto-selects: uv if system Python is missing or < 3.14, otherwise python3 -m venv. After the script finishes, run "source .venv/bin/activate" in your shell. Pass -y to skip venv creation and install with system Python instead. OPTIONS -h, --help Show this help message and exit. --uv Use uv to create the virtual environment (skips prompt). --no-uv Use python3 -m venv instead of uv (skips prompt). Requires Python 3.14+ to be available on the system. -y Non-interactive mode — use system Python directly instead of creating a virtual environment. noreset Reuse the dependency cache (~/.llmdbench_dependencies_checked) from a previous run instead of re-checking everything. CACHE The script records which tools and packages have already been verified in ~/.llmdbench_dependencies_checked. By default each run resets the cache; pass "noreset" to keep it. HELP } # --------------------------------------------------------------------------- # OS detection # --------------------------------------------------------------------------- is_mac=$(uname -s | grep -i darwin || true) if [[ -n "$is_mac" ]]; then target_os=mac else target_os=linux # shellcheck disable=SC1091 [[ -f /etc/os-release ]] && source /etc/os-release if [[ $NAME == "Ubuntu" && ${_APT_GET_UPDATE_RUN} -eq 0 ]]; then sudo apt-get update export _APT_GET_UPDATE_RUN=1 fi cat /etc/os-release fi # --------------------------------------------------------------------------- # CLI flags # --------------------------------------------------------------------------- allow_system_python=false reset_cache=true use_uv=auto for arg in "$@"; do case $arg in -h|--help) show_help; exit 0 ;; -y) allow_system_python=true ;; --uv) use_uv=true ;; --no-uv) use_uv=false ;; noreset) reset_cache=false ;; esac done # --------------------------------------------------------------------------- # Cache file — skip already-checked items across invocations # --------------------------------------------------------------------------- dependencies_checked_file=~/.llmdbench_dependencies_checked if [[ "$reset_cache" == "true" ]]; then rm -f "$dependencies_checked_file" fi touch "$dependencies_checked_file" # --------------------------------------------------------------------------- # Package manager detection # --------------------------------------------------------------------------- if [[ "$target_os" == "mac" ]]; then PKG_MGR="brew install" elif command -v apt &>/dev/null; then PKG_MGR="sudo apt install -y" elif command -v apt-get &>/dev/null; then PKG_MGR="sudo apt-get install -y" elif command -v brew &>/dev/null; then PKG_MGR="brew install" elif command -v yum &>/dev/null; then PKG_MGR="sudo yum install -y" elif command -v dnf &>/dev/null; then PKG_MGR="sudo dnf install -y" else echo "WARNING: No supported package manager found (apt, brew, yum, dnf)" echo " System tool installation may fail." PKG_MGR="echo SKIP:" fi # --------------------------------------------------------------------------- # Python / pip detection — auto-creates a .venv if none is active # # If the system Python is missing or < 3.14, the script uses `uv` to create # a virtual environment with the correct Python version (similar to conda). # uv is installed automatically if not already present. # --------------------------------------------------------------------------- LLMDBENCH_VENV_DIR=${LLMDBENCH_VENV_DIR:-"${SCRIPT_DIR}/.venv"} LLMDBENCH_SYSTEM_PYTHON=${LLMDBENCH_SYSTEM_PYTHON:-python3} CREATED_VENV=false MIN_PYTHON="3.14" # Helper — check whether a python command meets the minimum version requirement _python_meets_min() { local cmd="$1" if ! command -v "$cmd" &>/dev/null; then return 1 fi local ver major minor ver=$("$cmd" -c 'import sys; print(".".join(map(str, sys.version_info[:2])))' 2>/dev/null) || return 1 major=$(echo "$ver" | cut -d. -f1) minor=$(echo "$ver" | cut -d. -f2) (( major > 3 || (major == 3 && minor >= 11) )) } # Helper — resolve a python command, preferring "python" then "python3" _set_python_cmds() { if command -v python &>/dev/null; then PYTHON_CMD="python" PIP_CMD="python -m pip" else PYTHON_CMD="python3" PIP_CMD="python3 -m pip" fi } # Helper — ensure uv is available, install if missing _ensure_uv() { if command -v uv &>/dev/null; then return 0 fi echo " uv not found — installing..." if ! curl -LsSf https://astral.sh/uv/install.sh | sh 2>/dev/null; then echo "ERROR: Failed to install uv." exit 1 fi # Add uv to PATH for the current session export PATH="${HOME}/.local/bin:${HOME}/.cargo/bin:${PATH}" if ! command -v uv &>/dev/null; then echo "ERROR: uv was installed but not found on PATH." exit 1 fi echo " uv installed: $(uv --version)" } _detected_venv="${VIRTUAL_ENV:-${CONDA_PREFIX:-}}" if [[ -n "$_detected_venv" && -d "$_detected_venv" ]]; then # Already inside a venv / conda env — use it as-is _set_python_cmds echo "Virtual environment detected: ${_detected_venv}" elif [[ "$allow_system_python" == "true" ]]; then PYTHON_CMD=$LLMDBENCH_SYSTEM_PYTHON PIP_CMD="$PYTHON_CMD -m pip" echo "Using system python3 (forced with -y flag)" else if [[ -d "$LLMDBENCH_VENV_DIR" ]]; then if grep -q "venv created." "$dependencies_checked_file" 2>/dev/null; then true else echo "Using existing virtual environment: ${LLMDBENCH_VENV_DIR}" echo "venv created." >> "$dependencies_checked_file" fi else echo "No virtual environment detected — creating ${LLMDBENCH_VENV_DIR} ..." # Resolve use_uv if still "auto" if [[ "$use_uv" == "auto" ]]; then if [[ -t 0 ]]; then # Interactive terminal — ask the user echo "" echo " uv can create the virtual environment and automatically download" echo " the correct Python version if your system Python is missing or too old." echo "" read -r -p " Use uv to manage the virtual environment? [y/N]: " _uv_answer case "${_uv_answer}" in [yY]|[yY][eE][sS]) use_uv=true ;; *) use_uv=false ;; esac else # Non-interactive (curl pipe) — use uv only if system python is inadequate if _python_meets_min python3; then use_uv=false else use_uv=true fi fi fi if [[ "$use_uv" == "true" ]]; then if command -v python3 &>/dev/null && ! _python_meets_min python3; then local_ver=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))' 2>/dev/null || echo "unknown") echo " System python3 is ${local_ver} (need ${MIN_PYTHON}+) — uv will obtain the right version." elif ! command -v python3 &>/dev/null; then echo " python3 not found — uv will obtain Python ${MIN_PYTHON}." fi _ensure_uv uv venv --seed --python "${MIN_PYTHON}" "$LLMDBENCH_VENV_DIR" elif _python_meets_min python3; then python3 -m venv "$LLMDBENCH_VENV_DIR" else if command -v python3 &>/dev/null; then local_ver=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))' 2>/dev/null || echo "unknown") echo "ERROR: Python ${MIN_PYTHON}+ is required but system python3 is ${local_ver}." else echo "ERROR: Python ${MIN_PYTHON}+ is required but python3 was not found." fi echo " Re-run with --uv to let uv download the correct Python version." exit 1 fi CREATED_VENV=true echo "Virtual environment created: ${LLMDBENCH_VENV_DIR}" echo "venv created." >> "$dependencies_checked_file" fi # shellcheck disable=SC1091 source "${LLMDBENCH_VENV_DIR}/bin/activate" _set_python_cmds fi # --------------------------------------------------------------------------- # Validate Python 3.14+ # --------------------------------------------------------------------------- if ! command -v ${PYTHON_CMD} &>/dev/null; then if [[ "$PYTHON_CMD" == "python" ]] && command -v python3 &>/dev/null; then PYTHON_CMD="python3" PIP_CMD="python3 -m pip" elif [[ "$PYTHON_CMD" == "python3" ]] && command -v python &>/dev/null; then PYTHON_CMD="python" PIP_CMD="python -m pip" else echo "ERROR: Neither python nor python3 found in PATH" exit 1 fi fi python_version=$(${PYTHON_CMD} -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') python_major=$(echo "${python_version}" | cut -d. -f1) python_minor=$(echo "${python_version}" | cut -d. -f2) if ! (( python_major > 3 || (python_major == 3 && python_minor >= 14) )); then echo "ERROR: Python 3.14+ required, but ${PYTHON_CMD} is version ${python_version}" exit 1 fi echo "Python ${python_version} — OK [arch: ${ARCH_UNAME} → ${ARCH_GO}]" if ! ${PIP_CMD} --version &>/dev/null; then echo "pip not found. Attempting to install..." if [[ "$target_os" == "linux" ]]; then ${PKG_MGR} python3-pip else echo "ERROR: pip not found. Please install it manually." exit 1 fi fi # =================================================================== # System tool checks # =================================================================== echo "" echo "=== System tools ===" # curl and git stay required: install.sh itself uses them to fetch the pinned # binaries and to clone the planner. tools="curl git helm helmfile" kube_tool="" if command -v kubectl &>/dev/null; then kube_tool="kubectl" elif command -v oc &>/dev/null; then kube_tool="oc" fi if [ -z "$kube_tool" ]; then echo " kubectl/oc -- NOT FOUND, attempting oc install..." tools="$tools oc" else printf " %-14s %-20s %s\n" "$kube_tool" "$($kube_tool version --client --short 2>/dev/null || $kube_tool version --client 2>/dev/null | head -1)" "" fi optional_tools="oc" # Installing oc would also replace the user's kubectl, so it is report-only. autoinstall_optional="" # --------------------------------------------------------------------------- # Version helper # --------------------------------------------------------------------------- tool_version() { local tool="$1" case "$tool" in curl) curl --version 2>&1 | head -1 | awk '{print $2}' ;; git) git --version 2>&1 | awk '{print $3}' ;; kubectl) kubectl version --client -o json 2>/dev/null \ | ${PYTHON_CMD} -c "import sys,json; print(json.load(sys.stdin)['clientVersion']['gitVersion'])" 2>/dev/null \ || kubectl version --client 2>&1 | head -1 ;; helm) helm version --short 2>&1 | tr -d '\n' ;; oc) oc version --client 2>&1 | head -1 | awk '{print $NF}' ;; helmfile) helmfile --version 2>&1 | awk '{print $NF}' ;; *) echo "(unknown)" ;; esac } # --------------------------------------------------------------------------- # Version comparison — returns 0 if ver1 >= ver2 # --------------------------------------------------------------------------- version_gte() { local ver1="${1}" ver2="${2}" local higher # Normalize a leading 'v'. Tools report versions inconsistently: # `helmfile --version` prints 'v1.1.3' while tool_version_for helmfile # is '1.5.1'. Without this, `sort -V` ranks 'v1.1.3' ABOVE '1.5.1' # (the 'v' breaks numeric ordering), so a stale helmfile is wrongly # judged up-to-date and never upgraded. ver1="${ver1#v}" ver2="${ver2#v}" [[ "$ver1" == "$ver2" ]] && return 0 [[ -z "$ver1" || "$ver1" == "(unknown)" ]] && return 1 [[ -z "$ver2" ]] && return 0 higher=$(printf "%s\n%s" "$ver1" "$ver2" | sort -V | tail -1) [[ "$higher" == "$ver1" ]] && return 0 return 1 } # --------------------------------------------------------------------------- # Status + reason for a pinned version we intentionally do NOT enforce. # $4 is the category word ("non-critical" | "optional") used in the message. # --------------------------------------------------------------------------- _pin_not_enforced() { local tool="$1" cur="$2" pin="$3" kind="$4" printf " %-14s %-20s %s\n" "$tool" "$cur" \ "(pinned ${pin} not enforced -- ${kind})" echo " by design the installer does not modify PATH for ${kind} tools, so the existing on-PATH '${tool}' is kept as-is." } # -------------------------------------------------------------------------------- # Per-tool Linux install helpers - — all now arch-aware via $ARCH_GO / $ARCH_UNAME # # Callers invoke these through a guarded eval (`... || `), and an # AND-OR list turns `set -e` off for the whole function body. So every step # whose failure would otherwise fall through to a `cp`/`mv` returns explicitly: # without that, a failed fetch installs whatever stale /tmp file is left over. # `curl -f` is part of the same contract, since a 404 body is a 0 exit status. # --------------------------------------------------------------------------------- install_helmfile_linux() { local version=$(tool_version_for helmfile) local oc_arch="${ARCH_UNAME}" if [ "${oc_arch}" = "s390x" ]; then #added step to skip helmfile if it already exists if command -v helmfile >/dev/null 2>&1; then current_version=$(helmfile --version | awk '{print $3}' | sed 's/^v//') if [ "$current_version" = "$version" ]; then echo "helmfile $current_version already installed" return 0 fi echo "helmfile — v$current_version below pinned $version; attempting install/upgrade..." fi rm -rf /tmp/helmfile git clone https://github.com/helmfile/helmfile.git /tmp/helmfile || return 1 cd /tmp/helmfile || exit 1 git fetch --tags # Without this guard a failed checkout builds master, i.e. an # unpinned helmfile that the version gate below happily accepts. git checkout "v${version}" || return 1 GOARCH=s390x GOOS=linux go build -o helmfile || return 1 sudo mv helmfile /usr/local/bin/ sudo chmod +x /usr/local/bin/helmfile else local pkg="helmfile_${version}_linux_${ARCH_GO}" curl -fsSL "https://github.com/helmfile/helmfile/releases/download/v${version}/${pkg}.tar.gz" \ -o "/tmp/${pkg}.tar.gz" || return 1 tar xzf "/tmp/${pkg}.tar.gz" -C /tmp || return 1 sudo cp -f /tmp/helmfile /usr/local/bin/helmfile fi } install_helm_linux() { # Pin to the exact Helm version from tool_version_for (Helm 4+). The old # get-helm-3 script always installed the latest Helm 3.x and ignored the # pin entirely, so the helm pin was never actually honored. local version version=$(tool_version_for helm) # e.g. v4.2.0 (already 'v'-prefixed) local pkg="helm-${version}-linux-${ARCH_GO}" curl -fsSL "https://get.helm.sh/${pkg}.tar.gz" -o "/tmp/${pkg}.tar.gz" \ || { echo "ERROR: Failed to download Helm ${version}"; exit 1; } tar xzf "/tmp/${pkg}.tar.gz" -C /tmp sudo cp -f "/tmp/linux-${ARCH_GO}/helm" /usr/local/bin/helm sudo chmod +x /usr/local/bin/helm helm version --short || { echo "ERROR: Helm installation verification failed"; exit 1; } } install_kubectl_linux() { local stable stable=$(curl -sL https://dl.k8s.io/release/stable.txt) curl -sL "https://dl.k8s.io/release/${stable}/bin/linux/${ARCH_GO}/kubectl" \ -o /tmp/kubectl chmod +x /tmp/kubectl sudo mv /tmp/kubectl /usr/local/bin/kubectl } install_oc_linux() { # oc mirrors use aarch64 / x86_64 naming, not Go-style local version=$(tool_version_for oc) local oc_arch="${ARCH_UNAME}" # x86_64 | aarch64 | ppc64le | s390x local oc_file="openshift-client-linux" [[ "$oc_arch" == "aarch64" ]] && oc_file="${oc_file}-arm64-rhel9" oc_file="${oc_file}.tar.gz" curl -fsSL "https://mirror.openshift.com/pub/openshift-v4/${oc_arch}/clients/ocp/stable/${oc_file}" \ -o "/tmp/${oc_file}" || return 1 tar xzf "/tmp/${oc_file}" -C /tmp || return 1 sudo mv /tmp/kubectl /usr/local/bin/ sudo mv /tmp/oc /usr/local/bin/ sudo chmod +x /usr/local/bin/oc sudo chmod +x /usr/local/bin/kubectl } install_curl_linux() { # version is read by the SBOM generator (util/generate_sbom.py) to track the pinned minimum local version=8_21_0 ${PKG_MGR} curl || true } # --------------------------------------------------------------------------- # Ensure PostgreSQL dev headers are present (required to build psycopg2 from # source on architectures that lack pre-built wheels, e.g. s390x, ppc64le). # --------------------------------------------------------------------------- install_pg_dev_deps() { if command -v pg_config &>/dev/null; then return 0 fi echo " pg_config not found — installing PostgreSQL dev headers..." if command -v dnf &>/dev/null; then sudo dnf install -y postgresql-devel python3-devel gcc || true elif command -v yum &>/dev/null; then sudo yum install -y postgresql-devel python3-devel gcc || true elif command -v apt-get &>/dev/null; then sudo apt-get install -y libpq-dev python3-dev gcc || true elif command -v apt &>/dev/null; then sudo apt install -y libpq-dev python3-dev gcc || true else echo " WARNING: Cannot install pg_config automatically. If planner install fails," echo " install postgresql-devel (rpm) or libpq-dev (deb) manually." fi } # --------------------------------------------------------------------------- # macOS install helpers — Homebrew handles arch transparently on both # Intel and Apple Silicon, so these are simple wrappers. # --------------------------------------------------------------------------- # `brew install` is a no-op when the formula is already present, so it never # upgrades a stale binary (this is why a pinned helmfile/helm could stay # outdated). Always follow with `brew upgrade` so the pin is honored; the # enforce loop re-verifies the resulting version >= the pin and fails loud # otherwise. macOS uses Homebrew (not pinned tarballs like Linux) because # Homebrew owns the PATH/prefix here and brew stable already tracks the pins. install_helmfile_mac() { brew install helmfile 2>/dev/null || true; brew upgrade helmfile 2>/dev/null || true; } install_helm_mac() { brew install helm 2>/dev/null || true; brew upgrade helm 2>/dev/null || true; } install_kubectl_mac() { brew install kubectl; } install_oc_mac() { brew install openshift-cli; } install_curl_mac() { brew install curl; } # --------------------------------------------------------------------------- # Check required tools (fail if missing, upgrade if outdated) # --------------------------------------------------------------------------- for tool in $tools; do if grep -q "${tool} already installed." "$dependencies_checked_file" 2>/dev/null; then continue fi if command -v "$tool" &>/dev/null; then current_ver=$(tool_version "$tool") expected_ver=$(tool_version_for "$tool") needs_upgrade=false if [[ -n "$expected_ver" ]] && ! version_gte "$current_ver" "$expected_ver"; then needs_upgrade=true fi if [[ "$needs_upgrade" == "true" ]]; then echo " ${tool} — ${current_ver} below pinned ${expected_ver}; attempting install/upgrade..." install_func="install_${tool}_${target_os}" if declare -F "$install_func" &>/dev/null; then # Best-effort, like the `${PKG_MGR} "$tool" || true` sibling # below: under `set -e` an unguarded eval kills the script # before the `command -v` re-check below gets to decide # whether the failure is actually fatal. Report the failure # here, so a broken installer is never explained away as the # deliberate "pin not enforced" case further down. eval "$install_func" || echo " WARNING: the install/upgrade command for ${tool} failed" if ! command -v "$tool" &>/dev/null; then echo "ERROR: Failed to upgrade ${tool}" exit 1 fi new_ver=$(tool_version "$tool") # Re-verify the installer actually produced a version that # satisfies the pin (previously assumed, so a no-op upgrade # was silently cached as success). Only helm/helmfile hard- # fail: a stale helmfile panics under Helm 4, and both are # brew-symlinked so the failure is actionable. Other tools # keep the prior lenient behavior -- many pins are documented # floors, and some (e.g. macOS keg-only curl) the package # manager cannot put on PATH, so blocking the whole install # on them is wrong. if [[ -n "$expected_ver" ]] && ! version_gte "$new_ver" "$expected_ver"; then if [[ "$tool" == "helm" || "$tool" == "helmfile" ]]; then echo "ERROR: ${tool} is still ${new_ver} after the upgrade" echo " attempt (required: >= ${expected_ver}). The" echo " installer did not produce the pinned version." exit 1 fi # Non-critical tool the package manager can't put on PATH # (macOS keg-only curl, or a non-brew binary earlier in # PATH). Print one honest line + reason; never a false # "(upgraded)", and never silently modify the user's PATH. _pin_not_enforced "$tool" "$new_ver" "$expected_ver" "non-critical" else printf " %-14s %-20s %s\n" "$tool" "$new_ver" "(upgraded -> ${new_ver})" fi echo "${tool} already installed." >> "$dependencies_checked_file" else echo " WARNING: No upgrade function available for ${tool}, keeping ${current_ver}" printf " %-14s %-20s %s\n" "$tool" "$current_ver" "" echo "${tool} already installed." >> "$dependencies_checked_file" fi else printf " %-14s %-20s %s\n" "$tool" "$current_ver" "" echo "${tool} already installed." >> "$dependencies_checked_file" fi else echo " ${tool} — NOT FOUND, attempting install..." expected_ver=$(tool_version_for "$tool") install_func="install_${tool}_${target_os}" if declare -F "$install_func" &>/dev/null; then eval "$install_func" || true else ${PKG_MGR} "$tool" || true fi if command -v "$tool" &>/dev/null; then new_ver=$(tool_version "$tool") if [[ -n "$expected_ver" ]] && ! version_gte "$new_ver" "$expected_ver"; then if [[ "$tool" == "helm" || "$tool" == "helmfile" ]]; then echo "ERROR: ${tool} installed as ${new_ver} but >= ${expected_ver}" echo " is required. The installer did not produce the" echo " pinned version." exit 1 fi echo " WARNING: ${tool} is ${new_ver}; pinned ${expected_ver}" echo " not applied (continuing -- non-critical tool)." fi printf " %-14s %-20s %s\n" "$tool" "$new_ver" "(newly installed)" echo "${tool} already installed." >> "$dependencies_checked_file" else echo "ERROR: Failed to install required tool: ${tool}" exit 1 fi fi done # --------------------------------------------------------------------------- # Ensure helm-diff plugin is installed # --------------------------------------------------------------------------- helm_diff_url="https://github.com/databus23/helm-diff" # The helm-diff pin depends on the Helm major version actually on PATH: # helm's own pin is enforced as a minimum (version_gte), so an existing # Helm 4 install is left in place even though the default pin below is # Helm 3.x. Match the plugin build to whichever Helm is really installed. helm_major=0 if command -v helm &>/dev/null; then helm_major=$(helm version --short 2>/dev/null | sed -n 's/^v\([0-9][0-9]*\).*/\1/p') fi if [[ "${helm_major:-0}" -ge 4 ]]; then helm_diff_version=$(tool_version_for helm-diff-v4) else helm_diff_version=$(tool_version_for helm-diff) fi _install_helm_diff() { # Helm 4 requires plugin verification by default; helm-diff ships no # provenance artifacts, so fall back to --verify=false on failure. helm plugin install "${helm_diff_url}" --version "${helm_diff_version}" &>/dev/null \ || helm plugin install "${helm_diff_url}" --version "${helm_diff_version}" --verify=false &>/dev/null \ || { echo "ERROR: Failed to install helm-diff plugin"; exit 1; } } if command -v helm &>/dev/null; then installed_diff_ver=$(helm plugin list 2>/dev/null | awk '$1=="diff"{print $2}') want="${helm_diff_version#v}" if [[ -z "$installed_diff_ver" ]]; then echo " helm-diff -- NOT FOUND, installing ${helm_diff_version}..." _install_helm_diff diff_state="(newly installed)" elif [[ "${installed_diff_ver#v}" != "$want" ]]; then # A pre-Helm-4 helm-diff (built against the Helm 3 SDK) will fail to # load under Helm 4 and break `helmfile apply`. Reinstall the pin. echo " helm-diff -- ${installed_diff_ver} != pinned ${helm_diff_version}, reinstalling..." helm plugin uninstall diff 2>/dev/null || true _install_helm_diff diff_state="(reinstalled)" else diff_state="" fi final_diff_ver=$(helm plugin list 2>/dev/null | awk '$1=="diff"{print $2}') if [[ "${final_diff_ver#v}" != "$want" ]]; then echo "ERROR: helm-diff is ${final_diff_ver:-} after install" echo " (required: ${helm_diff_version}). Aborting." exit 1 fi printf " %-14s %-20s %s\n" "helm-diff" "$final_diff_ver" "$diff_state" fi # --------------------------------------------------------------------------- # Check optional tools (warn but don't fail, upgrade if outdated) # --------------------------------------------------------------------------- for tool in $optional_tools; do if grep -q "${tool} already installed." "$dependencies_checked_file" 2>/dev/null; then continue fi if command -v "$tool" &>/dev/null; then current_ver=$(tool_version "$tool") expected_ver=$(tool_version_for "$tool") needs_upgrade=false if [[ -n "$expected_ver" ]] && ! version_gte "$current_ver" "$expected_ver"; then needs_upgrade=true fi if [[ "$needs_upgrade" == "true" ]]; then echo " ${tool} — ${current_ver} below pinned ${expected_ver}; attempting install/upgrade..." install_func="install_${tool}_${target_os}" if declare -F "$install_func" &>/dev/null; then eval "$install_func" || echo " WARNING: the install/upgrade command for ${tool} failed" if command -v "$tool" &>/dev/null; then new_ver=$(tool_version "$tool") # Optional tools never hard-fail. Re-verify so we don't # claim "(upgraded)" when the on-PATH version did not # actually change (e.g. a non-brew oc shadowing brew's). if [[ -n "$expected_ver" ]] && ! version_gte "$new_ver" "$expected_ver"; then _pin_not_enforced "$tool" "$new_ver" "$expected_ver" "optional" else printf " %-14s %-20s %s\n" "$tool" "$new_ver" "(upgraded -> ${new_ver})" fi echo "${tool} already installed." >> "$dependencies_checked_file" else echo " WARNING: Failed to upgrade optional tool ${tool}, keeping ${current_ver}" printf " %-14s %-20s %s\n" "$tool" "$current_ver" "" echo "${tool} already installed." >> "$dependencies_checked_file" fi else echo " WARNING: No upgrade function available for ${tool}, keeping ${current_ver}" printf " %-14s %-20s %s\n" "$tool" "$current_ver" "" echo "${tool} already installed." >> "$dependencies_checked_file" fi else printf " %-14s %-20s %s\n" "$tool" "$current_ver" "" echo "${tool} already installed." >> "$dependencies_checked_file" fi elif [[ " $autoinstall_optional " != *" $tool "* ]]; then printf " %-14s %-20s %s\n" "$tool" "—" "(optional, not found)" else echo " ${tool} — NOT FOUND, attempting optional install..." expected_ver=$(tool_version_for "$tool") install_func="install_${tool}_${target_os}" if declare -F "$install_func" &>/dev/null; then eval "$install_func" || true else ${PKG_MGR} "$tool" || true fi if command -v "$tool" &>/dev/null; then new_ver=$(tool_version "$tool") if [[ -n "$expected_ver" ]] && ! version_gte "$new_ver" "$expected_ver"; then echo " WARNING: ${tool} is ${new_ver}; pinned ${expected_ver}" echo " not applied (continuing -- optional tool)." fi printf " %-14s %-20s %s\n" "$tool" "$new_ver" "(newly installed)" echo "${tool} already installed." >> "$dependencies_checked_file" else # No cache line on failure, so a later run retries. printf " %-14s %-20s %s\n" "$tool" "—" "(optional, install failed -- continuing)" fi fi done # =================================================================== # Python package installation # =================================================================== echo "" echo "=== Python packages ===" print_pkg() { local name="$1" status="$2" local ver ver=$(_pip_isolated show "$name" 2>/dev/null | awk '/^Version:/{print $2}') ver="${ver:---}" printf " %-22s %-14s %s\n" "$name" "$ver" "$status" } # 0. Install the in-repo Benchmark Report library first, so the # llmd-benchmark-report requirement below resolves against the local # checkout rather than PyPI (works pre-publish and for unreleased # schema changes). if _pip_isolated install -e "${SCRIPT_DIR}/benchmark-report" --quiet; then print_pkg llmd-benchmark-report "(installed)" else echo "ERROR: Failed to install llmd-benchmark-report!" exit 1 fi # 1. Install llmdbenchmark (editable) if grep -q "llmdbenchmark is already installed." "$dependencies_checked_file" 2>/dev/null; then print_pkg llmdbenchmark "" else if _pip_isolated install -e "${SCRIPT_DIR}" --quiet; then print_pkg llmdbenchmark "(installed)" echo "llmdbenchmark is already installed." >> "$dependencies_checked_file" else echo "ERROR: Failed to install llmdbenchmark!" exit 1 fi fi # --------------------------------------------------------------------------- # 2. Install planner (from llm-d-planner) # --------------------------------------------------------------------------- PLANNER_GIT="git+https://github.com/llm-d-incubation/llm-d-planner.git@v0.1.0" if grep -q "planner is already installed." "$dependencies_checked_file" 2>/dev/null; then print_pkg planner "" else # psycopg2-binary is a planner dependency. On architectures without pre-built # wheels (s390x, ppc64le, older arm64 builds) pip falls back to compiling from # source and requires pg_config / PostgreSQL dev headers. We ensure those are # present first, then force the binary wheel where available so we never # needlessly compile from source. if [[ "$target_os" == "linux" ]]; then install_pg_dev_deps fi _pip_isolated install psycopg2-binary --only-binary=:all: --quiet 2>/dev/null \ || true # if no wheel exists for this arch, fall through to source build above if _pip_isolated install "${PLANNER_GIT}" --quiet; then print_pkg planner "(installed)" echo "planner is already installed." >> "$dependencies_checked_file" else echo "ERROR: Failed to install planner (llm-d-planner)!" exit 1 fi fi # 3. Show key dependencies echo "" echo " Dependencies:" for pkg in PyYAML Jinja2 requests kubernetes pykube-ng \ GitPython huggingface_hub transformers packaging \ pydantic scipy pandas numpy; do ver=$(_pip_isolated show "$pkg" 2>/dev/null | awk '/^Version:/{print $2}') if [[ -n "$ver" ]]; then printf " %-22s %s\n" "$pkg" "$ver" fi done # 4. Verify imports echo "" import_ok=true if ! ${PYTHON_CMD} -c "import llmdbenchmark" 2>/dev/null; then echo "WARNING: llmdbenchmark installed but not importable" import_ok=false fi if ! ${PYTHON_CMD} -c "import planner" 2>/dev/null; then echo "WARNING: planner installed but not importable" import_ok=false fi if ! ${PYTHON_CMD} -c "from planner.capacity_planner import model_memory_req" 2>/dev/null; then echo "WARNING: planner.capacity_planner not importable" import_ok=false fi if [[ "$import_ok" == "true" ]]; then echo "All imports verified." fi # =================================================================== # Pre-commit hook setup -- only when git is available AND we're inside # a working tree AND the repo ships a .pre-commit-config.yaml. This is # best-effort: a failure here logs a warning but does NOT abort the # install. # =================================================================== echo "" echo "=== Pre-commit hooks ===" precommit_skip_reason="" if ! command -v git &>/dev/null; then precommit_skip_reason="git not found" elif ! git -C "${SCRIPT_DIR}" rev-parse --git-dir &>/dev/null; then precommit_skip_reason="${SCRIPT_DIR} is not a git working tree" elif [[ ! -f "${SCRIPT_DIR}/.pre-commit-config.yaml" ]]; then precommit_skip_reason=".pre-commit-config.yaml not found" fi # NOTE: install.sh wipes "$dependencies_checked_file" at the start of # every run unless the user passes the `noreset` argument. So the cache # check below only avoids work when a previous invocation used `noreset`. # Without `noreset`, this section runs every time -- but `pip install` # and `pre-commit install` are both idempotent, so re-running is safe # (just adds a few seconds). # # The cache hits only when both hook stages registered. precommit_cache_hit=false if [[ -z "$precommit_skip_reason" ]] && \ [[ -f "$dependencies_checked_file" ]] && \ grep -Fq "pre-commit hooks installed." "$dependencies_checked_file" && \ grep -Fq "pre-push hook installed." "$dependencies_checked_file"; then precommit_cache_hit=true fi if [[ -n "$precommit_skip_reason" ]]; then echo " skipped: ${precommit_skip_reason}" elif [[ "$precommit_cache_hit" == "true" ]]; then print_pkg pre-commit "" echo " hooks already registered (cache hit)" else # Install pre-commit framework + dev extras into the same venv. # If a .pre-commit_requirements.txt exists, prefer it (matches CI); # otherwise install just the framework. if [[ -f "${SCRIPT_DIR}/.pre-commit_requirements.txt" ]]; then precommit_install_target="-r ${SCRIPT_DIR}/.pre-commit_requirements.txt" else precommit_install_target="pre-commit" fi if ${PIP_CMD} install --quiet ${precommit_install_target} 2>/dev/null; then print_pkg pre-commit "(installed)" else echo " WARNING: failed to install pre-commit framework -- skipping hook registration" precommit_skip_reason="pip install failed" fi if [[ -z "$precommit_skip_reason" ]]; then # Register hooks for both stages. Use the venv's pre-commit # binary explicitly so we don't accidentally pick up a # system-wide install with a different version. precommit_bin="${LLMDBENCH_VENV_DIR}/bin/pre-commit" if [[ ! -x "$precommit_bin" ]]; then precommit_bin="$(command -v pre-commit 2>/dev/null || true)" fi if [[ -x "$precommit_bin" ]]; then (cd "${SCRIPT_DIR}" && \ "$precommit_bin" install --hook-type pre-commit >/dev/null 2>&1) && { echo " registered: pre-commit (run 'pre-commit run --all-files' to exercise)" echo "pre-commit hooks installed." >> "$dependencies_checked_file" } || echo " WARNING: pre-commit binary found but 'install' failed -- pre-commit hook NOT registered" (cd "${SCRIPT_DIR}" && \ "$precommit_bin" install --hook-type pre-push >/dev/null 2>&1) && { echo " registered: pre-push (unit tests run there)" echo "pre-push hook installed." >> "$dependencies_checked_file" } || echo " WARNING: could not register pre-push hook -- unit tests won't run on push" else echo " WARNING: pre-commit binary not found after install -- hooks NOT registered" fi fi fi echo "" echo "=== Done ===" echo "" echo "Reminder: Please activate the virtual environment in your shell:" echo "" echo " source ${LLMDBENCH_VENV_DIR}/bin/activate" echo "" echo "To deactivate the virtual environment in your shell:" echo "" echo " deactivate" echo "" echo ""