-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobolup.sh
More file actions
executable file
·1996 lines (1744 loc) · 60.3 KB
/
obolup.sh
File metadata and controls
executable file
·1996 lines (1744 loc) · 60.3 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
set -euo pipefail
# obolup.sh - Bootstrap installer for Obol Stack
# Usage: curl -sSL https://raw.githubusercontent.com/ObolNetwork/obol-stack/main/obolup.sh | bash
# Obol brand colors (24-bit true color — blog.obol.org/branding)
# Degrades gracefully: modern terminals render exact hex, older ones approximate.
OBOL_GREEN='\033[38;2;47;228;171m' # #2FE4AB — primary brand green
OBOL_DARK_GREEN='\033[38;2;15;124;118m' # #0F7C76 — dark green (success)
OBOL_CYAN='\033[38;2;60;210;221m' # #3CD2DD — info / cyan
OBOL_PURPLE='\033[38;2;145;103;228m' # #9167E4 — accent purple
OBOL_AMBER='\033[38;2;250;186;90m' # #FABA5A — warning amber
OBOL_RED='\033[38;2;221;96;60m' # #DD603C — error red-orange
OBOL_MUTED='\033[38;2;102;122;128m' # #667A80 — dim / muted gray
BOLD='\033[1m'
NC='\033[0m' # No Color
# Development mode detection
if [[ "${OBOL_DEVELOPMENT:-false}" == "true" ]]; then
# Get script directory for development mode
# Use -f to check for a real file, not /dev/fd/* from process substitution
if [[ -n "${BASH_SOURCE[0]:-}" && -f "${BASH_SOURCE[0]}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
# Fallback to current directory for curl | bash or bash <(...) cases
SCRIPT_DIR="$(pwd)"
fi
WORKSPACE_DIR="$SCRIPT_DIR/.workspace"
# Override directories to use local .workspace
OBOL_CONFIG_DIR="${OBOL_CONFIG_DIR:-$WORKSPACE_DIR/config}"
OBOL_DATA_DIR="${OBOL_DATA_DIR:-$WORKSPACE_DIR/data}"
OBOL_STATE_DIR="${OBOL_STATE_DIR:-$WORKSPACE_DIR/state}"
OBOL_BIN_DIR="${OBOL_BIN_DIR:-$WORKSPACE_DIR/bin}"
log_warn() { echo -e " ${OBOL_AMBER}${BOLD}!${NC} $1"; }
log_warn "Development mode enabled - using local .workspace directory"
else
# XDG Base Directory specification
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
XDG_BIN_HOME="${XDG_BIN_HOME:-$HOME/.local/bin}"
# Configuration directories with XDG defaults
OBOL_CONFIG_DIR="${OBOL_CONFIG_DIR:-$XDG_CONFIG_HOME/obol}"
OBOL_DATA_DIR="${OBOL_DATA_DIR:-$XDG_DATA_HOME/obol}"
OBOL_STATE_DIR="${OBOL_STATE_DIR:-$XDG_STATE_HOME/obol}"
OBOL_BIN_DIR="${OBOL_BIN_DIR:-$XDG_BIN_HOME}"
fi
# Pinned dependency versions
# Update these versions to upgrade dependencies across all installations
# renovate: datasource=github-releases depName=kubernetes/kubernetes
readonly KUBECTL_VERSION="1.35.3"
# renovate: datasource=github-releases depName=helm/helm
readonly HELM_VERSION="3.20.1"
# renovate: datasource=github-releases depName=k3d-io/k3d
readonly K3D_VERSION="5.8.3"
# renovate: datasource=github-releases depName=helmfile/helmfile
readonly HELMFILE_VERSION="1.4.3"
# renovate: datasource=github-releases depName=derailed/k9s
readonly K9S_VERSION="0.50.18"
# renovate: datasource=github-releases depName=databus23/helm-diff
readonly HELM_DIFF_VERSION="3.15.4"
# renovate: datasource=github-releases depName=ollama/ollama
readonly OLLAMA_VERSION="0.20.2"
# Must match internal/openclaw/OPENCLAW_VERSION (without "v" prefix).
# Tested by TestOpenClawVersionConsistency.
readonly OPENCLAW_VERSION="2026.4.15"
# Repository URL for building from source
readonly OBOL_REPO_URL="git@github.com:ObolNetwork/obol-stack.git"
# Logging functions — matching the Go CLI's ui package output style.
# Info/Error are top-level (no indent), Success/Warn are subordinate (2-space indent).
log_info() {
echo -e "${OBOL_GREEN}${BOLD}==>${NC} $1"
}
log_success() {
echo -e " ${OBOL_GREEN}${BOLD}✓${NC} $1"
}
log_warn() {
echo -e " ${OBOL_AMBER}${BOLD}!${NC} $1"
}
log_error() {
echo -e "${OBOL_RED}${BOLD}✗${NC} $1"
}
# Print dimmed secondary text (matches Go CLI's u.Dim)
log_dim() {
echo -e "${OBOL_MUTED}$1${NC}"
}
# Non-interactive install mode — set OBOL_ASSUME_YES=1 (or pass --yes/-y) to
# accept every prompt. Useful for CI, remote installs, and `curl | sh` runs
# where /dev/tty is unavailable.
ASSUME_YES=false
if [[ "${OBOL_ASSUME_YES:-}" == "1" || "${OBOL_ASSUME_YES:-}" == "true" ]]; then
ASSUME_YES=true
fi
for arg in "$@"; do
case "$arg" in
--yes | -y) ASSUME_YES=true ;;
esac
done
readonly ASSUME_YES
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check host prerequisites that the installer cannot provide itself.
# Binaries we download (helm, kubectl, k3d, etc.) are not checked here —
# only tools the user must install separately.
check_prerequisites() {
local missing=()
# Node.js 22+ / npm — preferred for openclaw CLI install.
# If missing, install_openclaw() will fall back to Docker image extraction.
# Only block here if neither npm NOR docker is available.
local need_npm=true
if command_exists openclaw; then
local oc_version
oc_version=$(openclaw --version 2>/dev/null | tr -d '[:space:]' || echo "")
if [[ -n "$oc_version" ]] && version_ge "$oc_version" "$OPENCLAW_VERSION"; then
need_npm=false
fi
fi
if [[ "$need_npm" == "true" ]]; then
if ! command_exists npm; then
if ! command_exists docker; then
missing+=("Node.js 22+ (npm) or Docker — required to install openclaw CLI")
fi
# npm missing but docker available — install_openclaw() will use Docker fallback
else
local node_major
node_major=$(node --version 2>/dev/null | sed 's/v//' | cut -d. -f1)
if [[ -z "$node_major" ]] || [[ "$node_major" -lt 22 ]]; then
if ! command_exists docker; then
missing+=("Node.js 22+ (found: v${node_major:-none}) or Docker — required for openclaw CLI")
fi
fi
fi
fi
if [[ ${#missing[@]} -gt 0 ]]; then
log_error "Missing prerequisites:"
echo ""
for dep in "${missing[@]}"; do
echo " • $dep"
done
echo ""
log_dim " Install the above, then re-run obolup.sh"
echo ""
return 1
fi
return 0
}
# Detect installation mode (install vs upgrade)
detect_installation_mode() {
if [[ -f "$OBOL_BIN_DIR/obol" ]]; then
echo "upgrade"
else
echo "install"
fi
}
# Check Docker installation and availability
check_docker() {
log_info "Checking Docker requirements..."
# Check if docker command exists
if ! command_exists docker; then
log_error "Docker is not installed"
echo ""
echo " Obol Stack requires Docker to run k3d clusters."
echo ""
echo " Install Docker:"
echo " • Ubuntu/Debian: https://docs.docker.com/engine/install/ubuntu/"
echo " • macOS: https://docs.docker.com/desktop/install/mac-install/"
echo " • Other: https://docs.docker.com/engine/install/"
echo ""
return 1
fi
# Check if Docker daemon is running and accessible
if ! docker info >/dev/null 2>&1; then
# Distinguish permission errors from daemon-not-running
local docker_err
docker_err=$(docker info 2>&1)
if echo "$docker_err" | grep -qi "permission denied"; then
log_error "Docker is installed but your user does not have permission to access it"
echo ""
echo " Add your user to the docker group and apply the change:"
echo " sudo usermod -aG docker \$USER"
echo " newgrp docker"
echo ""
log_dim " Then run this installer again."
echo ""
return 1
fi
if [[ "$(uname -s)" == "Linux" ]]; then
log_warn "Docker daemon is not running — attempting to start..."
# Try systemd first (apt/yum installs), then snap
if command_exists systemctl && systemctl list-unit-files docker.service >/dev/null 2>&1; then
sudo systemctl start docker 2>/dev/null && sleep 2
elif snap list docker >/dev/null 2>&1; then
sudo snap start docker 2>/dev/null && sleep 3
fi
elif [[ "$(uname -s)" == "Darwin" ]]; then
# Start Docker Desktop if it's installed but not running
if [[ -d "/Applications/Docker.app" ]]; then
log_warn "Docker Desktop is not running — starting it now..."
open -a Docker
# Docker Desktop can take a while to initialise; poll until ready
local wait_secs=0
while ! docker info >/dev/null 2>&1; do
if [[ $wait_secs -ge 60 ]]; then
break
fi
sleep 2
wait_secs=$((wait_secs + 2))
done
fi
fi
# Re-check after start attempt
if ! docker info >/dev/null 2>&1; then
log_error "Docker daemon is not running"
echo ""
echo " Please start the Docker daemon:"
if [[ "$(uname -s)" == "Linux" ]]; then
echo " • systemd: sudo systemctl start docker"
echo " • snap: sudo snap start docker"
else
echo " • macOS/Windows: Start Docker Desktop application"
fi
echo ""
log_dim " Then run this installer again."
echo ""
return 1
fi
log_success "Docker daemon started"
fi
# Check Docker version (require at least 20.10.0 for k3d compatibility)
local docker_version
docker_version=$(docker version --format '{{.Server.Version}}' 2>/dev/null || echo "0.0.0")
# Extract major.minor version
local major minor
major=$(echo "$docker_version" | cut -d. -f1)
minor=$(echo "$docker_version" | cut -d. -f2)
if [[ "$major" -lt 20 ]] || { [[ "$major" -eq 20 ]] && [[ "$minor" -lt 10 ]]; }; then
log_warn "Docker version $docker_version is older than recommended (20.10.0+)"
log_warn "k3d may not work correctly with older Docker versions"
fi
# Check Docker networking (ensure bridge network works)
if ! docker network ls >/dev/null 2>&1; then
log_error "Docker networking is not functional"
echo ""
echo "Docker networking is required for k3d clusters."
echo "Please check your Docker installation."
echo ""
return 1
fi
log_success "Docker is installed and running (version $docker_version)"
return 0
}
# Check if binary exists globally in PATH (excluding OBOL_BIN_DIR)
check_global_binary() {
local binary_name="$1"
# Get all matching binaries in PATH
local all_paths
all_paths=$(type -a -P "$binary_name" 2>/dev/null || true)
# Find first path that's NOT in OBOL_BIN_DIR
while IFS= read -r path; do
if [[ -n "$path" && "$path" != "$OBOL_BIN_DIR/$binary_name" ]]; then
# Found a global binary outside OBOL_BIN_DIR
echo "$path"
return 0
fi
done <<<"$all_paths"
return 1
}
# Create symlink to global binary in OBOL_BIN_DIR
create_binary_symlink() {
local binary_name="$1"
local global_path="$2"
local local_path="$OBOL_BIN_DIR/$binary_name"
# Detect and prevent circular symlinks.
# This can happen if a global binary path (e.g. from a previous dev install)
# already points to the location this script is trying to manage.
if [[ -L "$global_path" ]]; then
local link_target
link_target=$(readlink "$global_path" || echo "") # Handle readlink failure
if [[ "$link_target" == "$local_path" ]]; then
log_warn "Circular symlink detected for $binary_name."
log_warn " $global_path -> $local_path"
log_warn "Ignoring global binary to prevent loop. Will install fresh copy."
return 1 # Signal failure to prevent using this global binary
fi
fi
# Check if local path already exists
if [[ -e "$local_path" || -L "$local_path" ]]; then
# Check if it's already a symlink to the correct target
if [[ -L "$local_path" ]]; then
local current_target
current_target=$(readlink "$local_path")
if [[ "$current_target" == "$global_path" ]]; then
# Already correctly symlinked
return 0
fi
fi
# Remove existing file/symlink
rm -f "$local_path"
fi
# Create symlink
if ln -s "$global_path" "$local_path"; then
return 0
else
log_warn "Failed to create symlink for $binary_name"
return 1
fi
}
# Remove binary from OBOL_BIN_DIR if it's a broken symlink
remove_broken_symlink() {
local binary_name="$1"
local local_path="$OBOL_BIN_DIR/$binary_name"
# Check if it's a symlink
if [[ -L "$local_path" ]]; then
# Check if the symlink is broken (target doesn't exist)
if [[ ! -e "$local_path" ]]; then
rm -f "$local_path"
log_info "Removed broken symlink for $binary_name"
return 0
fi
fi
return 1
}
# Create directory structure
create_directories() {
log_info "Creating directory structure..."
# Config directories
mkdir -p "$OBOL_BIN_DIR"
mkdir -p "$OBOL_CONFIG_DIR"
mkdir -p "$OBOL_DATA_DIR"
mkdir -p "$OBOL_STATE_DIR"
log_success "Directories created"
}
# Get version information
get_version_info() {
local version="0.0.0" # Default semantic version
local git_commit="unknown"
local build_time
local git_dirty="false"
# Get build timestamp (YYYYMMDDHHMMSS format)
build_time=$(date -u +"%Y%m%d%H%M%S")
# Get git information if available
if command_exists git && [[ -d .git ]]; then
# Get short commit hash
git_commit=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Check if repo is dirty (has uncommitted changes)
if ! git diff --quiet 2>/dev/null || ! git diff --cached --quiet 2>/dev/null; then
git_dirty="true"
fi
# Try to get version from git tag
local git_tag
git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
if [[ -n "$git_tag" ]]; then
# Strip 'v' prefix if present
version="${git_tag#v}"
fi
fi
echo "$version" "$git_commit" "$build_time" "$git_dirty"
}
# Install obol binary for development mode (wrapper script)
install_dev_wrapper() {
log_info "Installing development wrapper script..."
# Get script directory
if [[ -n "${BASH_SOURCE[0]:-}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
SCRIPT_DIR="$(pwd)"
fi
local tmp_obol="$OBOL_BIN_DIR/obol.tmp"
# Create wrapper script that uses 'go run'
cat >"$tmp_obol" <<'EOF'
#!/usr/bin/env bash
# Obol CLI Development Wrapper
# This script runs the obol CLI using 'go run' for rapid development
# Find the project root (where obolup.sh is located)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# Run the CLI
cd "$SCRIPT_DIR" && exec go run -a ./cmd/obol "$@"
EOF
chmod +x "$tmp_obol"
mv "$tmp_obol" "$OBOL_BIN_DIR/obol"
log_success "Installed development wrapper at $OBOL_BIN_DIR/obol"
}
# Download and install binary from GitHub releases
download_release() {
local release_tag="$1"
log_info "Downloading release: $release_tag"
# Detect OS and architecture
local os arch
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="darwin" ;;
*)
log_error "Unsupported OS: $(uname -s)"
return 1
;;
esac
case "$(uname -m)" in
x86_64) arch="amd64" ;;
aarch64 | arm64) arch="arm64" ;;
*)
log_error "Unsupported architecture: $(uname -m)"
return 1
;;
esac
# Construct download URL
local binary_name="obol_${os}_${arch}"
local download_url="https://github.com/ObolNetwork/obol-stack/releases/download/${release_tag}/${binary_name}"
log_info "Downloading from: $download_url"
local tmp_obol="$OBOL_BIN_DIR/obol.tmp"
# Download binary
if command_exists curl; then
if ! curl -fsSL "$download_url" -o "$tmp_obol"; then
log_warn "Failed to download release $release_tag"
rm -f "$tmp_obol"
return 1
fi
elif command_exists wget; then
if ! wget -q "$download_url" -O "$tmp_obol"; then
log_warn "Failed to download release $release_tag"
rm -f "$tmp_obol"
return 1
fi
else
log_error "Neither curl nor wget is available"
return 1
fi
chmod +x "$tmp_obol"
mv "$tmp_obol" "$OBOL_BIN_DIR/obol"
log_success "Downloaded and installed release $release_tag"
return 0
}
# Build from source (latest or specific commit)
build_from_source() {
local build_ref="${1:-main}"
log_info "Building from source (ref: $build_ref)..."
# Create temporary directory
local tmp_dir
tmp_dir=$(mktemp -d)
trap "rm -rf '$tmp_dir'" EXIT
# TODO Perhaps git and golang need to be installed in tmp dir in order to build from source
log_info "Cloning repository..."
if ! git clone --depth 1 --branch "$build_ref" "$OBOL_REPO_URL" "$tmp_dir" 2>/dev/null; then
# If branch doesn't exist, try as a tag
if ! git clone "$OBOL_REPO_URL" "$tmp_dir" 2>/dev/null; then
log_error "Failed to clone repository"
return 1
fi
cd "$tmp_dir"
git checkout "$build_ref" 2>/dev/null || {
log_error "Failed to checkout ref: $build_ref"
return 1
}
fi
cd "$tmp_dir"
# Get version information
read -r version git_commit build_time git_dirty <<<"$(get_version_info)"
# Build binary
log_info "Building binary..."
local ldflags="-X github.com/ObolNetwork/obol-stack/internal/version.Version=$version"
ldflags="$ldflags -X github.com/ObolNetwork/obol-stack/internal/version.GitCommit=$git_commit"
ldflags="$ldflags -X github.com/ObolNetwork/obol-stack/internal/version.BuildTime=$build_time"
ldflags="$ldflags -X github.com/ObolNetwork/obol-stack/internal/version.GitDirty=$git_dirty"
local tmp_obol="$OBOL_BIN_DIR/obol.tmp"
if ! go build -ldflags "$ldflags" -o "$tmp_obol" ./cmd/obol; then
log_error "Failed to build binary"
rm -f "$tmp_obol"
return 1
fi
chmod +x "$tmp_obol"
mv "$tmp_obol" "$OBOL_BIN_DIR/obol"
log_success "Built and installed from source"
return 0
}
# Install obol binary
install_obol_binary() {
# Get current version if exists (for upgrade messaging)
local current_version=""
if [[ -f "$OBOL_BIN_DIR/obol" ]]; then
current_version=$("$OBOL_BIN_DIR/obol" version 2>/dev/null | head -1 || echo "")
fi
log_info "Installing obol binary..."
# Development mode: install wrapper script
if [[ "${OBOL_DEVELOPMENT:-false}" == "true" ]]; then
install_dev_wrapper
return 0
fi
# Production mode: handle OBOL_RELEASE
local release="${OBOL_RELEASE:-latest}"
if [[ "$release" == "latest" ]]; then
log_info "OBOL_RELEASE=latest: attempting to download latest release..."
# Try to get latest release tag from GitHub API
local latest_tag=""
if command_exists curl; then
# macOS-compatible: use sed instead of grep -oP
# Disable errexit temporarily to handle curl failure gracefully
set +e
latest_tag=$(curl -fsSL https://api.github.com/repos/ObolNetwork/obol-stack/releases/latest 2>/dev/null | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p')
set -e
fi
# If we got a tag, try to download it
if [[ -n "$latest_tag" ]]; then
if download_release "$latest_tag"; then
show_version_change "$current_version"
return 0
fi
log_warn "Download failed, falling back to building from source..."
else
log_info "No releases found, building from source..."
fi
# Fallback: build from source
build_from_source "main"
show_version_change "$current_version"
else
# Specific release requested
log_info "Attempting to download release: $release"
if download_release "$release"; then
show_version_change "$current_version"
return 0
fi
log_warn "Release $release not found, building from source..."
build_from_source "$release"
show_version_change "$current_version"
fi
}
# Show version change after upgrade
show_version_change() {
local old_version="$1"
# Get new version
local new_version=""
if [[ -f "$OBOL_BIN_DIR/obol" ]]; then
new_version=$("$OBOL_BIN_DIR/obol" version 2>/dev/null | head -1 || echo "")
fi
# Show upgrade message if versions are different
if [[ -n "$old_version" && -n "$new_version" ]]; then
if [[ "$old_version" != "$new_version" ]]; then
echo ""
log_success "Upgraded: $old_version → $new_version"
else
echo ""
log_success "Already at version: $new_version"
fi
elif [[ -n "$new_version" ]]; then
echo ""
log_success "Installed version: $new_version"
fi
}
# Copy bootstrap script to bin directory for easy upgrades
copy_bootstrap_script() {
# Skip in development mode
if [[ "${OBOL_DEVELOPMENT:-false}" == "true" ]]; then
log_info "Development mode: skipping bootstrap script copy"
return 0
fi
# Skip if we're already running from OBOL_BIN_DIR (avoid self-copy loop)
local script_path=""
if [[ -n "${BASH_SOURCE[0]:-}" ]]; then
script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
if [[ "$script_path" == "$OBOL_BIN_DIR/"* ]]; then
log_info "Already running from OBOL_BIN_DIR, skipping self-copy"
return 0
fi
fi
# Check if running from stdin (piped from curl) vs from a file
local script_source_url="https://raw.githubusercontent.com/ObolNetwork/obol-stack/main/obolup.sh"
if [[ -z "${BASH_SOURCE[0]:-}" ]] || [[ ! -f "${BASH_SOURCE[0]}" ]]; then
# Running from stdin (curl | bash) - download the script
log_info "Downloading bootstrap script to $OBOL_BIN_DIR/obolup.sh..."
if curl -fsSL "$script_source_url" -o "$OBOL_BIN_DIR/obolup.sh"; then
chmod +x "$OBOL_BIN_DIR/obolup.sh"
log_success "Bootstrap script installed at $OBOL_BIN_DIR/obolup.sh"
log_info "To upgrade in future, run: obolup.sh"
else
log_warn "Failed to download bootstrap script (non-critical)"
log_info "You can manually download it later with:"
echo ""
echo " curl -sSL $script_source_url -o $OBOL_BIN_DIR/obolup.sh"
echo " chmod +x $OBOL_BIN_DIR/obolup.sh"
echo ""
fi
else
# Running from a file - copy it
log_info "Copying bootstrap script to $OBOL_BIN_DIR/obolup.sh..."
if cp "${BASH_SOURCE[0]}" "$OBOL_BIN_DIR/obolup.sh"; then
chmod +x "$OBOL_BIN_DIR/obolup.sh"
log_success "Bootstrap script installed at $OBOL_BIN_DIR/obolup.sh"
log_info "To upgrade in future, run: obolup.sh"
else
log_warn "Failed to copy bootstrap script (non-critical)"
fi
fi
}
# Detect platform
detect_platform() {
local platform
case "$(uname -s)" in
Linux*)
platform="linux"
;;
Darwin*)
platform="darwin"
;;
*)
log_error "Unsupported platform: $(uname -s)"
exit 1
;;
esac
echo "$platform"
}
# Detect architecture
detect_arch() {
local arch
case "$(uname -m)" in
x86_64 | amd64)
arch="amd64"
;;
aarch64 | arm64)
arch="arm64"
;;
*)
log_error "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
echo "$arch"
}
# Compare semantic versions (returns 0 if v1 >= v2, 1 otherwise)
version_ge() {
local v1="$1"
local v2="$2"
# Remove 'v' prefix if present
v1="${v1#v}"
v2="${v2#v}"
# Simple version comparison using sort -V
if printf '%s\n%s\n' "$v2" "$v1" | sort -V -C 2>/dev/null; then
return 0
else
return 1
fi
}
# Install kubectl
install_kubectl() {
local platform=$(detect_platform)
local arch=$(detect_arch)
local current_version=""
# Remove broken symlink if exists
remove_broken_symlink "kubectl"
# Check for global kubectl first
local global_kubectl
if global_kubectl=$(check_global_binary "kubectl"); then
local global_version
global_version=$("$global_kubectl" version --client=true --output=json 2>/dev/null | grep gitVersion | head -1 | sed 's/.*"v\([0-9.]*\)".*/\1/' || echo "")
if [[ -n "$global_version" ]] && version_ge "$global_version" "$KUBECTL_VERSION"; then
if create_binary_symlink "kubectl" "$global_kubectl"; then
log_success "kubectl v$global_version already installed at: $global_kubectl (symlinked)"
else
log_success "kubectl v$global_version already installed at: $global_kubectl"
fi
return 0
fi
fi
# Check current version in OBOL_BIN_DIR
if [[ -f "$OBOL_BIN_DIR/kubectl" ]]; then
current_version=$("$OBOL_BIN_DIR/kubectl" version --client=true --output=json 2>/dev/null | grep gitVersion | head -1 | sed 's/.*"v\([0-9.]*\)".*/\1/' || echo "")
fi
# Use pinned version
local target_version="$KUBECTL_VERSION"
# Check if update needed
if [[ -n "$current_version" ]] && version_ge "$current_version" "$target_version"; then
log_success "kubectl v$current_version is up to date"
return 0
fi
if [[ -n "$current_version" ]]; then
log_info "Upgrading kubectl from v$current_version to v$target_version..."
else
log_info "Installing kubectl v$target_version..."
fi
# Download kubectl
local download_url="https://dl.k8s.io/release/v${target_version}/bin/${platform}/${arch}/kubectl"
if curl -sSL "$download_url" -o "$OBOL_BIN_DIR/kubectl.tmp"; then
chmod +x "$OBOL_BIN_DIR/kubectl.tmp"
mv "$OBOL_BIN_DIR/kubectl.tmp" "$OBOL_BIN_DIR/kubectl"
log_success "kubectl v$target_version installed"
else
log_error "Failed to download kubectl"
rm -f "$OBOL_BIN_DIR/kubectl.tmp"
return 1
fi
}
# Install helm
install_helm() {
local platform=$(detect_platform)
local arch=$(detect_arch)
local current_version=""
# Remove broken symlink if exists
remove_broken_symlink "helm"
# Check for global helm first
local global_helm
if global_helm=$(check_global_binary "helm"); then
local global_version
global_version=$("$global_helm" version --short 2>/dev/null | sed -n 's/v\([0-9.]*\).*/\1/p' || echo "")
if [[ -n "$global_version" ]] && version_ge "$global_version" "$HELM_VERSION"; then
if create_binary_symlink "helm" "$global_helm"; then
log_success "helm v$global_version already installed at: $global_helm (symlinked)"
else
log_success "helm v$global_version already installed at: $global_helm"
fi
return 0
fi
fi
# Check current version in OBOL_BIN_DIR
if [[ -f "$OBOL_BIN_DIR/helm" ]]; then
current_version=$("$OBOL_BIN_DIR/helm" version --short 2>/dev/null | sed -n 's/v\([0-9.]*\).*/\1/p' || echo "")
fi
# Use pinned version
local target_version="$HELM_VERSION"
# Check if update needed
if [[ -n "$current_version" ]] && version_ge "$current_version" "$target_version"; then
log_success "helm v$current_version is up to date"
return 0
fi
if [[ -n "$current_version" ]]; then
log_info "Upgrading helm from v$current_version to v$target_version..."
else
log_info "Installing helm v$target_version..."
fi
# Download and extract helm
local tmp_dir=$(mktemp -d)
local download_url="https://get.helm.sh/helm-v${target_version}-${platform}-${arch}.tar.gz"
if curl -sSL "$download_url" | tar xz -C "$tmp_dir" 2>/dev/null; then
mv "$tmp_dir/${platform}-${arch}/helm" "$OBOL_BIN_DIR/helm"
chmod +x "$OBOL_BIN_DIR/helm"
rm -rf "$tmp_dir"
log_success "helm v$target_version installed"
else
log_error "Failed to download helm"
rm -rf "$tmp_dir"
return 1
fi
}
# Install k3d
install_k3d() {
local platform=$(detect_platform)
local arch=$(detect_arch)
local current_version=""
# Remove broken symlink if exists
remove_broken_symlink "k3d"
# Check for global k3d first
local global_k3d
if global_k3d=$(check_global_binary "k3d"); then
local global_version
global_version=$("$global_k3d" version 2>/dev/null | sed -n 's/k3d version v\([0-9.]*\).*/\1/p' || echo "")
if [[ -n "$global_version" ]] && version_ge "$global_version" "$K3D_VERSION"; then
if create_binary_symlink "k3d" "$global_k3d"; then
log_success "k3d v$global_version already installed at: $global_k3d (symlinked)"
else
log_success "k3d v$global_version already installed at: $global_k3d"
fi
return 0
fi
fi
# Check current version in OBOL_BIN_DIR
if [[ -f "$OBOL_BIN_DIR/k3d" ]]; then
current_version=$("$OBOL_BIN_DIR/k3d" version 2>/dev/null | sed -n 's/k3d version v\([0-9.]*\).*/\1/p' || echo "")
fi
# Use pinned version
local target_version="$K3D_VERSION"
# Check if update needed
if [[ -n "$current_version" ]] && version_ge "$current_version" "$target_version"; then
log_success "k3d v$current_version is up to date"
return 0
fi
if [[ -n "$current_version" ]]; then
log_info "Upgrading k3d from v$current_version to v$target_version..."
else
log_info "Installing k3d v$target_version..."
fi
# Map platform/arch to k3d naming
local k3d_platform="$platform"
local k3d_arch="$arch"
# Download k3d
local download_url="https://github.com/k3d-io/k3d/releases/download/v${target_version}/k3d-${k3d_platform}-${k3d_arch}"
if curl -sSL "$download_url" -o "$OBOL_BIN_DIR/k3d.tmp"; then
chmod +x "$OBOL_BIN_DIR/k3d.tmp"
mv "$OBOL_BIN_DIR/k3d.tmp" "$OBOL_BIN_DIR/k3d"
log_success "k3d v$target_version installed"
else
log_error "Failed to download k3d"
rm -f "$OBOL_BIN_DIR/k3d.tmp"
return 1
fi
}
# Install helmfile
install_helmfile() {
local platform=$(detect_platform)
local arch=$(detect_arch)
local current_version=""
# Remove broken symlink if exists
remove_broken_symlink "helmfile"
# Check for global helmfile first
local global_helmfile
if global_helmfile=$(check_global_binary "helmfile"); then
local global_version
global_version=$("$global_helmfile" version 2>/dev/null | sed -n 's/.*Version[[:space:]]*v*\([0-9.]*\).*/\1/p' | head -1 || echo "")
if [[ -n "$global_version" ]] && version_ge "$global_version" "$HELMFILE_VERSION"; then
if create_binary_symlink "helmfile" "$global_helmfile"; then
log_success "helmfile v$global_version already installed at: $global_helmfile (symlinked)"
else
log_success "helmfile v$global_version already installed at: $global_helmfile"
fi
return 0
fi
fi
# Check current version in OBOL_BIN_DIR
if [[ -f "$OBOL_BIN_DIR/helmfile" ]]; then
current_version=$("$OBOL_BIN_DIR/helmfile" version 2>/dev/null | sed -n 's/.*Version[[:space:]]*v*\([0-9.]*\).*/\1/p' | head -1 || echo "")
fi
# Use pinned version
local target_version="$HELMFILE_VERSION"
# Check if update needed
if [[ -n "$current_version" ]] && version_ge "$current_version" "$target_version"; then
log_success "helmfile v$current_version is up to date"
return 0
fi
if [[ -n "$current_version" ]]; then
log_info "Upgrading helmfile from v$current_version to v$target_version..."
else
log_info "Installing helmfile v$target_version..."
fi
# Map platform/arch to helmfile naming
local helmfile_platform="$platform"
local helmfile_arch="$arch"
# Helmfile uses different naming for architectures
if [[ "$arch" == "amd64" ]]; then
helmfile_arch="amd64"
elif [[ "$arch" == "arm64" ]]; then
helmfile_arch="arm64"
fi
# Download and extract helmfile
local tmp_dir=$(mktemp -d)
local download_url="https://github.com/helmfile/helmfile/releases/download/v${target_version}/helmfile_${target_version}_${helmfile_platform}_${helmfile_arch}.tar.gz"
if curl -sSL "$download_url" | tar xz -C "$tmp_dir" 2>/dev/null; then
mv "$tmp_dir/helmfile" "$OBOL_BIN_DIR/helmfile"
chmod +x "$OBOL_BIN_DIR/helmfile"
rm -rf "$tmp_dir"
log_success "helmfile v$target_version installed"
else
log_error "Failed to download helmfile"
rm -rf "$tmp_dir"
return 1
fi
}
# Install helm-diff plugin
install_helm_diff() {
# Find helm binary (check OBOL_BIN_DIR first, then global PATH)
local helm_bin="$OBOL_BIN_DIR/helm"
if [[ ! -f "$helm_bin" ]]; then