-
Notifications
You must be signed in to change notification settings - Fork 469
Expand file tree
/
Copy pathinstall.sh
More file actions
515 lines (439 loc) · 15.4 KB
/
Copy pathinstall.sh
File metadata and controls
515 lines (439 loc) · 15.4 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
#!/bin/bash
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
set -Eeuo pipefail
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo ""
echo "ERROR: Installation failed at line $1 (exit code $exit_code)."
if [ -n "${LOG_FILE:-}" ] && [ -f "$LOG_FILE" ]; then
echo "Check $LOG_FILE for details."
fi
echo "Re-run with --verbose for more details."
fi
exit $exit_code
}
trap 'cleanup $LINENO' ERR
trap 'echo ""; echo "Installation interrupted."; exit 130' INT TERM
GIT_URL="https://github.com/open-edge-platform/geti.git"
GIT_BRANCH="nightly-2026.06.19"
usage() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
Install Intel Geti application and its dependencies.
Options:
-v, --verbose Show detailed output from all commands
-y, --yes Assume yes to all prompts (non-interactive mode)
-w, --work-dir Set the working directory (default: \$PWD/geti)
-h, --help Show this help message and exit
EOF
}
parse_args() {
VERBOSE=""
ASSUME_YES=""
WORK_DIR="$(pwd)/geti"
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--verbose)
VERBOSE=1
shift
;;
-y|--yes)
ASSUME_YES=1
shift
;;
-w|--work-dir)
if [[ -z "${2:-}" ]]; then
echo "Error: --work-dir requires a path argument."
exit 1
fi
WORK_DIR="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Error: unknown option '$1'"
usage
exit 1
;;
esac
done
BUILD_TOOLS_DIR="$WORK_DIR/.build"
UV_DIR="$BUILD_TOOLS_DIR/uv"
NVM_DIR="$BUILD_TOOLS_DIR/nvm"
LOG_FILE="$BUILD_TOOLS_DIR/.install.log"
}
confirm() {
local prompt="$1"
if [ -n "${ASSUME_YES:-}" ]; then
return 0
fi
local response
if [ -t 0 ]; then
read -rp "$prompt [Y/n]: " response
elif [ -e /dev/tty ]; then
read -rp "$prompt [Y/n]: " response </dev/tty
else
echo "Error: confirmation required but no terminal is available."
echo "Re-run with -y/--yes to skip prompts in non-interactive mode."
exit 1
fi
if [[ "${response,,}" =~ ^n(o)?$ ]]; then
return 1
fi
return 0
}
run_cmd() {
if [ -n "${VERBOSE:-}" ]; then
"$@"
else
"$@" >>"$LOG_FILE" 2>&1
fi
}
run_cmd_spinner() {
# Run a long command quietly (output to the log file) while showing an
# animated spinner, so the step never looks frozen. In verbose mode the
# full output is streamed instead.
local activity="$1"
shift
if [ -n "${VERBOSE:-}" ]; then
echo "${activity}..."
"$@"
return
fi
"$@" >>"$LOG_FILE" 2>&1 &
local pid=$!
local spin='|/-\'
local i=0
if [ -t 2 ]; then
while kill -0 "$pid" 2>/dev/null; do
i=$(( (i + 1) % 4 ))
printf "\r%s... %s" "$activity" "${spin:$i:1}" >&2
sleep 0.2
done
fi
local rc=0
wait "$pid" || rc=$?
if [ "$rc" -eq 0 ]; then
printf "\r%s... done \n" "$activity" >&2
else
printf "\r%s... failed\n" "$activity" >&2
return "$rc"
fi
}
get_required_uv_version() {
local version
version=$(grep -A 3 '\[tool\.uv\]' "$WORK_DIR/application/backend/pyproject.toml" \
| grep 'required-version' \
| sed -E 's/.*"[^0-9]*([0-9]+\.[0-9]+\.[0-9]+).*/\1/' || true)
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: could not parse uv version from pyproject.toml" >&2
return 1
fi
echo "$version"
}
get_required_node_version() {
local version
version=$(grep '"node"' "$WORK_DIR/application/ui/package.json" \
| sed -E 's/.*">=v?([0-9]+\.[0-9]+\.[0-9]+)".*/\1/')
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: could not parse node version from package.json" >&2
return 1
fi
echo "$version"
}
get_required_npm_version() {
local version
version=$(grep '"npm"' "$WORK_DIR/application/ui/package.json" \
| sed -E 's/.*">=([0-9]+\.[0-9]+\.[0-9]+)".*/\1/')
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: could not parse npm version from package.json" >&2
return 1
fi
echo "$version"
}
install_uv() {
local uv_version
uv_version=$(get_required_uv_version)
if [ -x "$UV_DIR/uv" ]; then
local installed_version
installed_version=$("$UV_DIR/uv" --version | awk '{print $2}')
if [ "$installed_version" = "$uv_version" ]; then
echo "uv $uv_version found in $UV_DIR"
return 0
else
echo "uv version mismatch: installed=$installed_version, required=$uv_version. Reinstalling..."
fi
fi
echo "Installing uv $uv_version to: $UV_DIR"
if ! confirm "Would you like to install uv now?"; then
echo "uv installation skipped. Cannot continue without uv."
exit 1
fi
if [ ! -d "$UV_DIR" ]; then
mkdir -p "$UV_DIR"
fi
run_cmd_spinner "Downloading and installing uv $uv_version" bash -c "curl --proto '=https' --tlsv1.2 -LsSf 'https://github.com/astral-sh/uv/releases/download/${uv_version}/uv-installer.sh' | env UV_INSTALL_DIR='$UV_DIR' sh"
echo "uv installation complete."
}
install_nvm() {
export NVM_DIR
if [ -s "$NVM_DIR/nvm.sh" ]; then
source "$NVM_DIR/nvm.sh"
echo "nvm found in $NVM_DIR."
return 0
fi
echo "Installing nvm to: $NVM_DIR"
if ! confirm "Would you like to install nvm now?"; then
echo "nvm installation skipped. Cannot continue without nvm."
exit 1
fi
if [ ! -d "$NVM_DIR" ]; then
mkdir -p "$NVM_DIR"
fi
run_cmd_spinner "Downloading and installing nvm" bash -c "curl -sS -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash"
source "$NVM_DIR/nvm.sh"
echo "nvm installation complete."
}
install_npm() {
local required_node_version required_npm_version
required_node_version=$(get_required_node_version)
required_npm_version=$(get_required_npm_version)
NPM_BIN="$NVM_DIR/versions/node/v${required_node_version}/bin/npm"
local node_bin installed_npm_version
node_bin="$(dirname "$NPM_BIN")"
if [ -x "$node_bin/node" ] && [ -x "$NPM_BIN" ]; then
installed_npm_version=$("$NPM_BIN" --version)
if [ "$(printf '%s\n' "$required_npm_version" "$installed_npm_version" | sort -V | head -n1)" = "$required_npm_version" ]; then
echo "node $required_node_version and npm $installed_npm_version found in $node_bin."
return 0
fi
echo "npm version too old: installed=$installed_npm_version, required>=$required_npm_version. Upgrading..."
run_cmd "$NPM_BIN" install -g "npm@$required_npm_version"
return 0
fi
echo "Required node $required_node_version not found in $NVM_DIR. Installing..."
run_cmd_spinner "Downloading and installing node $required_node_version" nvm install "$required_node_version"
installed_npm_version=$("$NPM_BIN" --version)
if [ "$(printf '%s\n' "$required_npm_version" "$installed_npm_version" | sort -V | head -n1)" != "$required_npm_version" ]; then
run_cmd "$NPM_BIN" install -g "npm@$required_npm_version"
fi
echo "node/npm installation complete: $node_bin"
}
detect_nvidia_gpus() {
local gpu_count=0
if command -v nvidia-smi &>/dev/null; then
gpu_count=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | wc -l || true)
if [ "$gpu_count" -gt 0 ]; then
echo "Detected $gpu_count NVIDIA GPU(s) via nvidia-smi:"
nvidia-smi --query-gpu=index,name,memory.total --format=csv,noheader 2>/dev/null
return 0
fi
fi
if [ -d /proc/driver/nvidia/gpus ]; then
gpu_count=$(ls /proc/driver/nvidia/gpus 2>/dev/null | wc -l)
if [ "$gpu_count" -gt 0 ]; then
echo "Detected $gpu_count NVIDIA GPU(s) via /proc/driver/nvidia/gpus"
return 0
fi
fi
if command -v lspci &>/dev/null; then
local gpus
gpus=$(lspci | grep -i 'nvidia' | grep -i 'vga\|3d\|display' || true)
if [ -n "$gpus" ]; then
gpu_count=$(echo "$gpus" | wc -l)
echo "Detected $gpu_count NVIDIA GPU(s) via lspci:"
echo "$gpus"
return 0
fi
fi
echo "No NVIDIA GPUs detected."
return 1
}
detect_intel_gpus() {
local gpu_count=0
if command -v xpu-smi &>/dev/null; then
gpu_count=$(xpu-smi discovery 2>/dev/null | grep -c 'Device ID' || true)
if [ "$gpu_count" -gt 0 ]; then
echo "Detected $gpu_count Intel GPU(s) via xpu-smi:"
xpu-smi discovery 2>/dev/null
return 0
fi
fi
if command -v sycl-ls &>/dev/null; then
local intel_devs
intel_devs=$(sycl-ls 2>/dev/null | grep -i 'intel' || true)
if [ -n "$intel_devs" ]; then
gpu_count=$(echo "$intel_devs" | wc -l)
echo "Detected Intel GPU(s) via sycl-ls:"
echo "$intel_devs"
return 0
fi
fi
if command -v lspci &>/dev/null; then
local gpus
gpus=$(lspci | grep -i 'intel' | grep -i 'vga\|3d\|display' || true)
if [ -n "$gpus" ]; then
gpu_count=$(echo "$gpus" | wc -l)
echo "Detected $gpu_count Intel GPU(s) via lspci:"
echo "$gpus"
return 0
fi
fi
echo "No Intel GPUs detected."
return 1
}
preflight_checks() {
if ! command -v git &>/dev/null; then
echo "Error: git is not installed. Please install git and try again."
exit 1
fi
if ! command -v curl &>/dev/null; then
echo "Error: curl is not installed. Please install curl and try again."
exit 1
fi
}
ensure_source_code() {
if [ ! -d "$WORK_DIR" ]; then
echo "Cloning Intel Geti repository from $GIT_URL..."
echo "This can take several minutes depending on your connection."
git -c advice.detachedHead=false clone --progress --branch "$GIT_BRANCH" "$GIT_URL" "$WORK_DIR"
else
echo "Work directory $WORK_DIR already exists, skipping clone."
local remote_url
remote_url=$(git -C "$WORK_DIR" remote get-url origin 2>/dev/null)
if [ "$remote_url" != "$GIT_URL" ]; then
echo "Error: $WORK_DIR remote origin is '$remote_url', expected '$GIT_URL'."
echo "Remove $WORK_DIR and re-run the installer."
exit 1
fi
local current_sha expected_sha
current_sha=$(git -C "$WORK_DIR" rev-parse HEAD 2>/dev/null)
# Fetch: try as tag first, then as branch
git -C "$WORK_DIR" fetch origin "refs/tags/${GIT_BRANCH}:refs/tags/${GIT_BRANCH}" --force 2>/dev/null \
|| git -C "$WORK_DIR" fetch origin "$GIT_BRANCH" --tags 2>/dev/null \
|| true
# Resolve: try as tag first, then as remote branch
expected_sha=$(git -C "$WORK_DIR" rev-parse "refs/tags/$GIT_BRANCH" 2>/dev/null) \
|| expected_sha=$(git -C "$WORK_DIR" rev-parse "origin/$GIT_BRANCH" 2>/dev/null) \
|| true
if [ -z "$expected_sha" ] || ! echo "$expected_sha" | grep -qE '^[0-9a-f]{40}$'; then
echo "Error: Could not resolve ref '$GIT_BRANCH'. Ensure it exists on the remote."
exit 1
fi
if [ "$current_sha" != "$expected_sha" ]; then
echo "Switching to $GIT_BRANCH..."
git -c advice.detachedHead=false -C "$WORK_DIR" checkout --force "$GIT_BRANCH"
fi
fi
}
install_build_tools() {
install_uv
install_nvm
install_npm
}
detect_hardware() {
HAS_NVIDIA_GPU=false
HAS_INTEL_GPU=false
if detect_nvidia_gpus; then
HAS_NVIDIA_GPU=true
fi
if detect_intel_gpus; then
HAS_INTEL_GPU=true
fi
if [ "$HAS_NVIDIA_GPU" = true ]; then
ACCELERATOR="cuda"
elif [ "$HAS_INTEL_GPU" = true ]; then
ACCELERATOR="xpu"
else
ACCELERATOR="cpu"
fi
export ACCELERATOR
}
build_backend() {
echo "Building Python environment using accelerator: $ACCELERATOR"
echo "This downloads PyTorch, OpenVINO and other large packages and can take several minutes."
cd "$WORK_DIR/application/backend"
# uv shows its own progress meter; do not suppress it so the user gets feedback.
"$UV_DIR/uv" sync --frozen --extra mqtt --extra "$ACCELERATOR"
echo "Generating OpenAPI specification..."
PYTHONPATH=. "$UV_DIR/uv" run --no-sync app/cli.py gen-api --target-path openapi.json
cp openapi.json ../ui/src/api/openapi-spec.json
}
build_frontend() {
cd "$WORK_DIR/application/ui"
export npm_config_yes=true
# --foreground-scripts surfaces lifecycle-script errors (e.g. the
# 'preinstall' UI-package clone) in the log instead of a generic exit code.
run_cmd_spinner "Installing UI dependencies (this may take several minutes)" "$NPM_BIN" ci --foreground-scripts
run_cmd_spinner "Building API client" "$NPM_BIN" run build:api
run_cmd_spinner "Building UI (this may take several minutes)" env ASSET_PREFIX="/html" "$NPM_BIN" run build
}
deploy_frontend() {
local html_dir="$WORK_DIR/application/backend/html"
echo "Copying built UI to backend html directory..."
if [ -d "$html_dir" ]; then
rm -rf "$html_dir"
fi
mkdir "$html_dir"
cp -r "$WORK_DIR/application/ui/dist/"* "$html_dir"
}
register_shell_cmd() {
local begin_marker="# BEGIN Intel Geti"
local end_marker="# END Intel Geti"
local shell_profile="${HOME}/.bashrc"
if [ -n "${ZSH_VERSION:-}" ] || [[ "$SHELL" == */zsh ]]; then
shell_profile="${HOME}/.zshrc"
fi
# Remove old marker block if present (idempotent update)
if grep -qF "$begin_marker" "$shell_profile" 2>/dev/null; then
sed -i "/$begin_marker/,/$end_marker/d" "$shell_profile"
fi
{
echo ""
echo "$begin_marker"
echo "function geti { (cd '$WORK_DIR/application/backend' && STATIC_FILES_DIR=html '$UV_DIR/uv' run app/main.py \"\$@\"); }"
echo "$end_marker"
} >> "$shell_profile"
echo "Function 'geti' written to $shell_profile"
echo "Run 'source $shell_profile' to activate it in the current session."
echo "Example: HOST=0.0.0.0 PORT=8080 geti"
}
main() {
parse_args "$@"
preflight_checks
ensure_source_code
# Initialize log file and build tools directory
mkdir -p "$BUILD_TOOLS_DIR"
: > "$LOG_FILE"
install_build_tools
detect_hardware
build_backend
build_frontend
deploy_frontend
register_shell_cmd
run_app
}
run_app() {
echo ""
echo "Installation complete! Starting Intel Geti..."
# Resolve the URL the user should open. The server binds to 0.0.0.0 by
# default, which is not a valid address to open in a browser, so use
# localhost. Honour PORT/HOST overrides if the user set them.
local port="${PORT:-7860}"
local browser_host="${HOST:-localhost}"
if [ "$browser_host" = "0.0.0.0" ]; then
browser_host="localhost"
fi
local url="http://${browser_host}:${port}"
echo ""
echo "Geti will be available at: $url"
echo ""
cd "$WORK_DIR/application/backend"
STATIC_FILES_DIR=html "$UV_DIR/uv" run app/main.py
}
main "$@"