forked from llm-d/llm-d-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1066 lines (974 loc) · 43.7 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·1066 lines (974 loc) · 43.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/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:
# LLMDBENCH_BRANCH=my-branch curl -sSL ... | 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
export LLMDBENCH_CONTROL_PCMD=${LLMDBENCH_CONTROL_PCMD:-python}
# ---------------------------------------------------------------------------
# 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" ;;
yq) echo "v4.53.3" ;;
helmfile) echo "1.5.1" ;;
helm) echo "v3.19.0" ;;
helm-diff) echo "v3.13.0" ;;
oc) echo "4.18.0" ;;
kustomize) echo "v5.8.1" ;;
crane) echo "0.21.7" ;;
skopeo) echo "1.20.1" ;;
jq) echo "1.8.2" ;;
*) 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.11+ and pip
2. Checks for required system tools (curl, git, kubectl, helm, helmfile,
skopeo, kustomize, jq, yq, crane)
3. Checks for 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.11.
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.11, 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.11+ 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.11, 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.11"
# 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.11+
# ---------------------------------------------------------------------------
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 >= 11) )); then
echo "ERROR: Python 3.11+ 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 ==="
tools="curl git helm helmfile skopeo kustomize jq yq crane"
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"
# ---------------------------------------------------------------------------
# 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}' ;;
kustomize) kustomize version 2>&1 | head -1 ;;
jq) jq --version 2>&1 ;;
yq) yq --version 2>&1 | awk '{print $NF}' ;;
skopeo) skopeo --version 2>&1 | awk '{print $NF}' ;;
crane) crane version 2>&1 | tr -d '\n' ;;
*) 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
# ---------------------------------------------------------------------------------
install_yq_linux() {
local version=$(tool_version_for yq)
local binary="yq_linux_${ARCH_GO}"
curl -sL "https://github.com/mikefarah/yq/releases/download/${version}/${binary}" -o "/tmp/${binary}"
chmod +x "/tmp/${binary}"
sudo cp -f "/tmp/${binary}" /usr/local/bin/yq
}
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
cd /tmp/helmfile || exit 1
git fetch --tags
git checkout "v${version}"
GOARCH=s390x GOOS=linux go build -o helmfile
sudo mv helmfile /usr/local/bin/
sudo chmod +x /usr/local/bin/helmfile
else
local pkg="helmfile_${version}_linux_${ARCH_GO}"
curl -sL "https://github.com/helmfile/helmfile/releases/download/v${version}/${pkg}.tar.gz" \
-o "/tmp/${pkg}.tar.gz"
tar xzf "/tmp/${pkg}.tar.gz" -C /tmp
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 -sL "https://mirror.openshift.com/pub/openshift-v4/${oc_arch}/clients/ocp/stable/${oc_file}" \
-o "/tmp/${oc_file}"
tar xzf "/tmp/${oc_file}" -C /tmp
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_kustomize_linux() {
local version="$(tool_version_for kustomize)"
local arch
arch=$(uname -m)
local go_arch="amd64"
[[ "$arch" == "aarch64" ]] && go_arch="arm64"
curl -sL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${version}/kustomize_${version}_linux_${go_arch}.tar.gz" \
-o "/tmp/kustomize.tar.gz"
tar xzf /tmp/kustomize.tar.gz -C /tmp kustomize
sudo mv /tmp/kustomize /usr/local/bin/
sudo chmod +x /usr/local/bin/kustomize
}
install_crane_linux() {
local version
version="v$(tool_version_for crane)"
# go-containerregistry release tarballs use Go arch names (X86_64 capitalised)
local go_arch_cap
case "$ARCH_GO" in
amd64) go_arch_cap="x86_64" ;;
arm64) go_arch_cap="arm64" ;;
arm) go_arch_cap="armv6" ;;
ppc64le) go_arch_cap="ppc64le" ;;
s390x) go_arch_cap="s390x" ;;
*) go_arch_cap="x86_64" ;;
esac
local pkg="go-containerregistry_Linux_${go_arch_cap}"
curl -sL "https://github.com/google/go-containerregistry/releases/download/${version}/${pkg}.tar.gz" \
-o "/tmp/${pkg}.tar.gz"
tar xzf "/tmp/${pkg}.tar.gz" -C /tmp crane
sudo cp -f /tmp/crane /usr/local/bin/crane
sudo chmod +x /usr/local/bin/crane
}
install_skopeo_linux() {
local version=$(tool_version_for skopeo)
local pkg="skopeo-linux-${ARCH_GO}"
if curl -sfL "https://github.com/lework/skopeo-binary/releases/download/v${version}/${pkg}" \
-o "/tmp/${pkg}"; then
chmod +x "/tmp/${pkg}"
sudo cp -f "/tmp/${pkg}" /usr/local/bin/skopeo
rm -f "/tmp/${pkg}"
else
echo " Pre-built binary for skopeo ${version} not available; falling back to package manager"
${PKG_MGR} skopeo || true
fi
}
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
}
install_jq_linux() {
local version
version="$(tool_version_for jq)"
local arch_name
case "$ARCH_GO" in
amd64) arch_name="amd64" ;;
arm64) arch_name="arm64" ;;
ppc64le) arch_name="ppc64el" ;;
s390x) arch_name="s390x" ;;
*) arch_name="amd64" ;;
esac
if curl -sfL "https://github.com/jqlang/jq/releases/download/jq-${version}/jq-linux-${arch_name}" \
-o /tmp/jq; then
chmod +x /tmp/jq
sudo cp -f /tmp/jq /usr/local/bin/jq
rm -f /tmp/jq
else
echo " Pre-built binary for jq ${version} not available; falling back to package manager"
${PKG_MGR} jq || true
fi
}
# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------
install_yq_mac() { brew install yq; }
# `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_kustomize_mac(){ brew install kustomize; }
install_crane_mac() { brew install crane; }
install_skopeo_mac() { brew install skopeo; }
install_curl_mac() { brew install curl; }
install_jq_mac() { brew install jq; }
# ---------------------------------------------------------------------------
# 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
eval "$install_func"
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"
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"
helm_diff_version=$(tool_version_for helm-diff) # e.g. v3.15.7
_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:-<missing>} 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"
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
else
printf " %-14s %-20s %s\n" "$tool" "—" "(optional, not found)"
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"
}
# 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 kubernetes-asyncio \
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. Hooks are wired for the pre-commit stage only -- CI is the
# gate before push, no need to duplicate the local hooks at push time.
# ===================================================================
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