Repository navigation
Expand file tree
/
Copy pathget-ods.sh
More file actions
8000
div>
executable file
·507 lines (449 loc) · 18.6 KB
/
Copy pathget-ods.sh
File metadata and controls
executable file
·507 lines (449 loc) · 18.6 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
#!/bin/bash
# ODS Bootstrap Installer
# curl -fsSL https://install.osmantic.com/ods.sh | bash
#
# Detects OS, clones repo, runs installer.
set -euo pipefail
# Anchor CWD to a known-good directory. Without this, a user who just
# uninstalled ODS and immediately re-runs the bootstrap from the
# same terminal will land here with a deleted working directory — `git
# clone` then fails with `fatal: Unable to read current working directory`
# and the user sees a misleading "check your internet connection" message.
ODS_BOOTSTRAP_ROOT="${HOME:-/tmp}"
if ! cd "$ODS_BOOTSTRAP_ROOT" 2>/dev/null; then
ODS_BOOTSTRAP_ROOT="/tmp"
cd "$ODS_BOOTSTRAP_ROOT" 2>/dev/null || {
echo "[error] Cannot find a usable working directory (\$HOME and /tmp both inaccessible)." >&2
exit 1
}
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
REPO_URL="${ODS_REPO_URL:-https://github.com/Osmantic/ODS.git}"
INSTALL_DIR="${ODS_INSTALL_DIR:-$ODS_BOOTSTRAP_ROOT/ods}"
PRE_ODS_INSTALL_DIR="${ODS_LEGACY_INSTALL_DIR:-}"
ODS_REF="${ODS_REF:-${ODS_BOOTSTRAP_REF:-}}"
BOOTSTRAP_FORCE=false
BOOTSTRAP_NON_INTERACTIVE=false
for _arg in "$@"; do
case "$_arg" in
--force) BOOTSTRAP_FORCE=true ;;
--non-interactive) BOOTSTRAP_NON_INTERACTIVE=true ;;
esac
done
log() { echo -e "${CYAN}[ods]${NC} $1"; }
success() { echo -e "${GREEN}[ ok ]${NC} $1"; }
warn() { echo -e "${YELLOW}[warn ]${NC} $1"; }
error() { echo -e "${RED}[error]${NC} $1"; exit 1; }
format_git_clone_error() {
local clone_err="$1"
case "$clone_err" in
*"Unable to read current working directory"*|*"getcwd"*)
error "git could not read the current working directory. This usually means the directory you launched from has been deleted (e.g. you uninstalled ODS and re-ran the bootstrap from the same shell). Run \`cd ~\` and re-run the bootstrap." ;;
*"Could not resolve host"*|*"Failed to connect"*|*"Connection refused"*|*"Network is unreachable"*)
error "Failed to reach github.com. Check your internet connection or proxy settings.\n git said: $clone_err" ;;
*"Permission denied"*|*"could not create"*)
error "git failed to write to $TEMP_DIR (permissions). Check that /tmp is writable.\n git said: $clone_err" ;;
*)
error "Failed to clone repository.\n git said: $clone_err" ;;
esac
}
remove_install_dir() {
local target_dir="$1"
if rm -rf -- "$target_dir" 2>/dev/null; then
return 0
fi
if command -v sudo >/dev/null 2>&1 && sudo -n true 2>/dev/null; then
warn "Normal removal failed; retrying with sudo for root-owned container data."
sudo -n rm -rf -- "$target_dir" && return 0
fi
return 1
}
is_truthy() {
case "${1:-}" in
1|true|TRUE|yes|YES|y|Y) return 0 ;;
*) return 1 ;;
esac
}
ods_ref_is_exact_sha() {
[[ "${1:-}" =~ ^[0-9a-fA-F]{40}$ ]]
}
checkout_requested_sha_ref() {
local ref="${1:-}"
local fetch_err=""
local checkout_err=""
[[ -n "$ref" ]] || return 0
ods_ref_is_exact_sha "$ref" || return 0
fetch_err=$(git fetch --depth 1 origin "$ref" 2>&1) || true
if ! checkout_err=$(git checkout --detach "$ref" 2>&1); then
error "Failed to check out repository ref $ref after cloning.
git fetch said: ${fetch_err:-already present in shallow clone}
g
8000
it checkout said: $checkout_err"
fi
}
_ods_is_install_backup_dir() {
local candidate_name="${1%/}"
candidate_name="${candidate_name##*/}"
case "$candidate_name" in
*.backup-[0-9]*|backup-[0-9]*) return 0 ;;
*) return 1 ;;
esac
}
_ods_is_related_install_dir() {
local candidate="$1"
local compose_file=""
[[ -d "$candidate" ]] || return 1
[[ -f "$candidate/.env" || -d "$candidate/data" ]] || return 1
if [[ -f "$candidate/docker-compose.base.yml" ]]; then
compose_file="$candidate/docker-compose.base.yml"
elif [[ -f "$candidate/docker-compose.yml" ]]; then
compose_file="$candidate/docker-compose.yml"
else
return 1
fi
grep -Eq '^[[:space:]]{2}open-webui:[[:space:]]*$' "$compose_file" || return 1
grep -Eq '^[[:space:]]{2}dashboard-api:[[:space:]]*$' "$compose_file" || return 1
grep -Eq '^[[:space:]]{2}(llama-server|litellm):[[:space:]]*$' "$compose_file"
}
_ods_related_compose_containers() {
command -v docker >/dev/null 2>&1 || return 0
docker ps -a \
--format '{{.Names}}|{{.Label "com.docker.compose.project"}}|{{.Label "com.docker.compose.service"}}' \
2>/dev/null |
awk -F '|' '
$2 != "" {
project = $2
if (names[project] == "") {
names[project] = $1
} else {
names[project] = names[project] " " $1
}
if ($3 == "open-webui") open_webui[project] = 1
if ($3 == "dashboard-api") dashboard_api[project] = 1
if ($3 == "llama-server" || $3 == "litellm") inference[project] = 1
}
END {
for (project in names) {
if (open_webui[project] && dashboard_api[project] && inference[project]) {
print names[project]
}
}
}
'
}
refuse_legacy_install() {
is_truthy "${ODS_ALLOW_LEGACY_PARALLEL:-}" && return 0
local findings=()
local candidate=""
local related_containers=""
if [[ -n "$PRE_ODS_INSTALL_DIR" && -d "$PRE_ODS_INSTALL_DIR" ]] && {
[[ -f "$PRE_ODS_INSTALL_DIR/.env" ]] ||
[[ -f "$PRE_ODS_INSTALL_DIR/docker-compose.yml" ]] ||
[[ -d "$PRE_ODS_INSTALL_DIR/data" ]]
}; then
findings+=("install directory: $PRE_ODS_INSTALL_DIR")
fi
if [[ -d "$ODS_BOOTSTRAP_ROOT" ]]; then
while IFS= read -r -d '' candidate; do
[[ "${candidate%/}" == "${INSTALL_DIR%/}" ]] && continue
[[ -n "$PRE_ODS_INSTALL_DIR" && "${candidate%/}" == "${PRE_ODS_INSTALL_DIR%/}" ]] && continue
_ods_is_install_backup_dir "$candidate" && continue
if _ods_is_related_install_dir "$candidate"; then
findings+=("related install directory: $candidate")
fi
done < <(find "$ODS_BOOTSTRAP_ROOT" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) -print0 2>/dev/null)
fi
related_containers="$(_ods_related_compose_containers || true)"
if [[ -n "$related_containers" ]]; then
findings+=("related Compose containers: $(printf '%s\n' "$related_containers" | tr '\n' ' ')")
fi
if (( ${#findings[@]} > 0 )); then
echo ""
warn "Existing related install detected before first ODS install."
echo ""
echo "ODS uses the same default ports and service roles as the older stack."
echo "Resolve the old install intentionally before installing ODS, or run in"
echo "parallel only after choosing separate ports and an explicit install dir."
echo ""
echo "Detected:"
printf ' - %s\n' "${findings[@]}"
echo ""
echo "To proceed after you have isolated the old stack:"
echo " ODS_ALLOW_LEGACY_PARALLEL=1 ODS_INSTALL_DIR=\"$INSTALL_DIR\" bash get-ods.sh"
echo ""
exit 1
fi
}
# ── Banner ──────────────────────────────────────
echo ""
echo -e "${BOLD}${BLUE}"
cat << 'BANNER'
OOOOO DDDD SSSSS
OO OO DD DD SS
OO OO DD DD SSS
OO OO DD DD SS
OOOOO DDDD SSSS
BANNER
echo -e "${NC}"
echo -e "${BOLD} Osmantic Deployment System - Local AI for Everyone${NC}"
echo ""
# ── Detect OS ──────────────────────────────────────
detect_os() {
if [[ -f /proc/version ]] && grep -qi microsoft /proc/version 2>/dev/null; then
echo "wsl"
elif [[ "${OSTYPE:-}" == "darwin"* ]]; then
echo "macos"
elif [[ "${OSTYPE:-}" == linux* ]]; then
echo "linux"
else
echo "unknown"
fi
}
OS=$(detect_os)
log "Detected OS: $OS"
case "$OS" in
linux|wsl)
success "Linux/WSL detected — full support"
;;
macos)
warn "macOS detected — limited GPU support (Apple Silicon MLX coming soon)"
;;
unknown)
error "Unsupported OS. ODS requires Linux, WSL, or macOS."
;;
esac
# ── Check prerequisites ──────────────────────────────
log "Checking prerequisites..."
# Docker check (informational — the installer auto-installs Docker if missing)
if command -v docker &> /dev/null; then
success "Docker found: $(docker --version | head -1)"
else
warn "Docker not found — the installer will attempt to install it"
fi
# GPU check (early info — real detection happens in the installer)
_gpu_found=false
for _v in /sys/class/drm/card*/device/vendor; do
case "$(cat "$_v" 2>/dev/null)" in
0x10de) # NVIDIA
if command -v nvidia-smi &> /dev/null; then
# Capture all output then take the first line in-shell. Piping
# `... | head -1` SIGPIPEs nvidia-smi (~17% on multi-GPU hosts):
# head closes the pipe after line 1, nvidia-smi exits 141, and
# pipefail propagates the failure → `set -e` aborts the bootstrap.
_info=$(nvidia-smi --query-gpu=name,memory.total --format=csv,noheader 2>/dev/null) || _info=""
_info=${_info%%$'\n'*}
[[ -n "$_info" ]] && success "NVIDIA GPU detected: $_info" && _gpu_found=true
else
success "NVIDIA GPU detected (driver not yet installed — installer will handle it)"
_gpu_found=true
fi ;;
0x1002) # AMD
success "AMD GPU detected"
_gpu_found=true ;;
0x8086) # Intel — only flag if it looks like Arc (discrete)
if lspci 2>/dev/null | grep -qi 'VGA.*Intel.*Arc'; then
success "Intel Arc GPU detected"
_gpu_found=true
fi ;;
esac
$_gpu_found && break
done
if ! $_gpu_found; then
warn "No GPU detected — CPU-only mode will be used (slow but functional)"
fi
# git
if command -v git &> /dev/null; then
success "git found: $(git --version | head -1)"
else
log "Installing git..."
if [[ "$OS" == "macos" ]]; then
xcode-select --install 2>/dev/null || true
command -v git &> /dev/null || error "Please install git: https://git-scm.com"
else
if command -v apt-get &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq git
elif command -v dnf &> /dev/null; then
sudo dnf install -y -q git
elif command -v yum &> /dev/null; then
sudo yum install -y -q git
elif command -v pacman &> /dev/null; then
sudo pacman -Sy --noconfirm git
elif command -v zypper &> /dev/null; then
sudo zypper --non-interactive --gpg-auto-import-keys refresh
sudo zypper --non-interactive install -y git
else
error "Cannot install git automatically. Please install git and re-run."
fi
fi
success "git installed"
fi
# curl
if command -v curl &> /dev/null; then
success "curl found"
else
log "Installing curl..."
if command -v apt-get &> /dev/null; then
sudo apt-get install -y -qq curl
elif command -v dnf &> /dev/null; then
sudo dnf install -y -q curl
elif command -v yum &> /dev/null; then
sudo yum install -y -q curl
elif command -v pacman &> /dev/null; then
sudo pacman -Sy --noconfirm curl
elif command -v zypper &> /dev/null; then
sudo zypper --non-interactive --gpg-auto-import-keys refresh
sudo zypper --non-interactive install -y curl
else
error "Please install curl and re-run."
fi
success "curl installed"
fi
# docker (the installer auto-installs Docker if missing — don't block here)
if command -v docker &> /dev/null; then
success "docker found: $(docker --version | head -1)"
if docker compose version &> /dev/null || docker-compose --version &> /dev/null; then
success "docker compose found"
else
warn "Docker Compose not found — the installer will attempt to set it up"
fi
else
warn "Docker not found — the installer will attempt to install it"
fi
# GPU pre-check already done above — real detection happens in the installer
# ── Check for existing installation ──────────────────
if [[ -d "$INSTALL_DIR" ]]; then
if [[ -f "$INSTALL_DIR/.env" ]]; then
warn "ODS already installed at $INSTALL_DIR"
echo ""
echo " To start: cd $INSTALL_DIR && docker compose up -d"
echo " To reinstall: rm -rf $INSTALL_DIR && re-run this script"
echo " To update: cd $INSTALL_DIR && ./ods-cli update"
echo ""
exit 0
else
warn "Directory exists but incomplete install at $INSTALL_DIR"
echo ""
if [[ "$BOOTSTRAP_FORCE" == "true" ]]; then
echo " Removing incomplete install because --force was provided."
remove_install_dir "$INSTALL_DIR" || error "Failed to remove incomplete install at $INSTALL_DIR. Try: sudo rm -rf \"$INSTALL_DIR\""
elif [[ "$BOOTSTRAP_NON_INTERACTIVE" == "true" ]]; then
echo " Aborting. Re-run with --force to remove it automatically, or remove manually with: rm -rf $INSTALL_DIR"
exit 1
else
echo -n " Remove and reinstall? [y/N] "
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
remove_install_dir "$INSTALL_DIR" || error "Failed to remove incomplete install at $INSTALL_DIR. Try: sudo rm -rf \"$INSTALL_DIR\""
else
echo " Aborting. Remove manually with: rm -rf $INSTALL_DIR"
exit 1
fi
fi
fi
fi
# ── Clone repository ──────────────────────────────
refuse_legacy_install
log "Cloning ODS..."
if [[ -n "$ODS_REF" ]]; then
log "Using repository ref: $ODS_REF"
fi
if [[ "$REPO_URL" == file://* ]]; then
_repo_path="${REPO_URL#file://}"
git config --global --add safe.directory "$_repo_path" 2>/dev/null || true
git config --global --add safe.directory "$_repo_path/.git" 2>/dev/null || true
fi
# Clone just the ods subdirectory using sparse checkout
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT
clone_args=(--depth 1 --filter=blob:none --sparse)
if [[ -n "$ODS_REF" ]] && ! ods_ref_is_exact_sha "$ODS_REF"; then
clone_args+=(--branch "$ODS_REF")
fi
_clone_err=$(git clone "${clone_args[@]}" "$REPO_URL" "$TEMP_DIR/repo" 2>&1) || {
format_git_clone_error "$_clone_err"
}
echo "$_clone_err" | tail -1
cd "$TEMP_DIR/repo"
checkout_requested_sha_ref "$ODS_REF"
git sparse-checkout set ods 2>/dev/null || {
# Fallback: full clone if sparse checkout fails
cd "$ODS_BOOTSTRAP_ROOT"
rm -rf "$TEMP_DIR/repo"
fallback_clone_args=(--depth 1)
if [[ -n "$ODS_REF" ]] && ! ods_ref_is_exact_sha "$ODS_REF"; then
fallback_clone_args+=(--branch "$ODS_REF")
fi
git clone "${fallback_clone_args[@]}" "$REPO_URL" "$TEMP_DIR/repo" 2>&1 | tail -1 || \
error "Failed to clone repository (fallback full clone also failed)."
cd "$TEMP_DIR/repo"
checkout_requested_sha_ref "$ODS_REF"
}
# Move ods to install location (exclude dev-only files)
if [[ -d "$TEMP_DIR/repo/ods" ]]; then
# Use rsync to exclude development files not needed at runtime
if command -v rsync >/dev/null 2>&1; then
rsync -a \
--exclude='tests/' \
--exclude='docs/' \
--exclude='examples/' \
--exclude='.github/' \
--exclude='*.md' \
--exclude='.shellcheckrc' \
--exclude='PSScriptAnalyzerSettings.psd1' \
--exclude='test-stack.sh' \
--exclude='.gitignore' \
--exclude='__pycache__/' \
--exclude='*.pyc' \
--exclude='.pytest_cache/' \
--exclude='node_modules/' \
--include='LICENSE' \
"$TEMP_DIR/repo/ods/" "$INSTALL_DIR/"
else
# Fallback to cp if rsync not available
cp -r "$TEMP_DIR/repo/ods" "$INSTALL_DIR"
# Remove dev-only files after copy
rm -rf "$INSTALL_DIR/tests" "$INSTALL_DIR/docs" "$INSTALL_DIR/examples" "$INSTALL_DIR/.github" 2>/dev/null || true
rm -f "$INSTALL_DIR"/*.md "$INSTALL_DIR/.shellcheckrc" "$INSTALL_DIR/PSScriptAnalyzerSettings.psd1" "$INSTALL_DIR/test-stack.sh" "$INSTALL_DIR/.gitignore" 2>/dev/null || true
# Keep LICENSE file
[[ -f "$TEMP_DIR/repo/ods/LICENSE" ]] && cp "$TEMP_DIR/repo/ods/LICENSE" "$INSTALL_DIR/" 2>/dev/null || true
fi
else
error "ods directory not found in repository."
fi
success "Cloned to $INSTALL_DIR"
# ── Bundle extensions-library templates ──────â”
5134
€───────
# The dashboard's Extensions page reads from data/extensions-library/. The
# source library now ships inside ods/extensions/library/, which the
# rsync above copies as part of the product tree. Without it, dashboard-api returns:
# 503 {"detail":"Extensions library is unavailable"}
# on every install. Bundle the templates inside the install dir so the
# installer can find them deterministically regardless of where it's invoked.
if [[ -d "$TEMP_DIR/repo/ods/extensions/library" ]]; then
if rm -rf "$INSTALL_DIR/extensions-library-bundle" \
&& mkdir -p "$INSTALL_DIR/extensions-library-bundle" \
&& cp -R "$TEMP_DIR/repo/ods/extensions/library/." "$INSTALL_DIR/extensions-library-bundle/"; then
success "Bundled extensions-library templates"
else
warn "Failed to bundle extensions-library — Extensions page may 503"
fi
else
warn "ods/extensions/library not in clone — Extensions page will 503"
fi
# ── Make scripts executable ──────────────────────────
chmod +x "$INSTALL_DIR/install.sh" 2>/dev/null || true
chmod +x "$INSTALL_DIR/ods-cli" 2>/dev/null || true
chmod +x "$INSTALL_DIR/scripts/"*.sh 2>/dev/null || true
# Note: tests/ directory excluded from installation
# ── Run installer ──────────────────────────────
echo ""
log "Launching ODS installer..."
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
cd "$INSTALL_DIR"
exec ./install.sh "$@"