-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·837 lines (755 loc) · 21.1 KB
/
install.sh
File metadata and controls
executable file
·837 lines (755 loc) · 21.1 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
#!/bin/sh
set -e
# Stellar CLI installation script
# Usage: curl -fsSL https://raw.githubusercontent.com/stellar/stellar-cli/main/install.sh | sh
# Or with options: curl -fsSL https://raw.githubusercontent.com/stellar/stellar-cli/main/install.sh | sh -s -- --user
REPO="stellar/stellar-cli"
BINARY_NAME="stellar"
command_exists() {
command -v "$1" >/dev/null 2>&1
}
run_as_root() {
if [ "$(id -u)" = "0" ]; then
"$@"
return
fi
if command_exists sudo; then
sudo "$@"
return
fi
echo "Warning: '$*' requires root privileges, but neither root access nor sudo is available." >&2
return 1
}
detect_linux_distro() {
if [ -r /etc/os-release ]; then
# shellcheck disable=SC1091
. /etc/os-release
if [ -n "$ID" ]; then
echo "$ID"
return
fi
fi
echo "unknown"
}
detect_linux_libc() {
if command_exists getconf; then
if getconf GNU_LIBC_VERSION >/dev/null 2>&1; then
echo "glibc"
return
fi
fi
if command_exists ldd; then
if ldd --version 2>&1 | grep -qi musl; then
echo "musl"
return
fi
if ldd --version 2>&1 | grep -qi "gnu libc"; then
echo "glibc"
return
fi
fi
if [ -e /lib/ld-musl-x86_64.so.1 ] || [ -e /lib/ld-musl-aarch64.so.1 ]; then
echo "musl"
return
fi
echo "unknown"
}
suggest_dependency_install() {
missing_cmds="$1"
# Map missing command names to their actual package names
pkgs=""
for cmd in $missing_cmds; do
case "$cmd" in
sed) [ "$OS" = "macos" ] && pkgs="$pkgs gnu-sed" || pkgs="$pkgs sed" ;;
tar) [ "$OS" = "macos" ] && pkgs="$pkgs gnu-tar" || pkgs="$pkgs tar" ;;
mktemp) pkgs="$pkgs coreutils" ;;
*) pkgs="$pkgs $cmd" ;;
esac
done
pkgs="${pkgs# }"
if [ "$OS" = "macos" ]; then
cat <<EOF
Install missing dependencies using Homebrew:
brew install $pkgs
EOF
return
fi
if command_exists apt-get; then
cat <<EOF
Install missing dependencies on Debian/Ubuntu:
${SUDO}apt-get update && ${SUDO}apt-get install -y $pkgs
EOF
elif command_exists dnf; then
cat <<EOF
Install missing dependencies on Fedora/RHEL:
${SUDO}dnf install -y $pkgs
EOF
elif command_exists yum; then
cat <<EOF
Install missing dependencies on CentOS/RHEL:
${SUDO}yum install -y $pkgs
EOF
elif command_exists pacman; then
cat <<EOF
Install missing dependencies on Arch:
${SUDO}pacman -S --needed $pkgs
EOF
elif command_exists zypper; then
cat <<EOF
Install missing dependencies on openSUSE:
${SUDO}zypper install -y $pkgs
EOF
else
cat <<EOF
Detected Linux distro: $(detect_linux_distro)
Install packages providing these commands with your distro package manager: $missing_cmds
EOF
fi
}
check_dependencies() {
missing=""
for cmd in curl grep sed tar mktemp; do
if ! command_exists "$cmd"; then
missing="$missing $cmd"
fi
done
if [ -n "$missing" ]; then
missing="${missing# }"
echo "Error: Missing required command(s): $missing"
echo ""
suggest_dependency_install "$missing"
echo ""
echo "After installing dependencies, re-run this installer."
exit 1
fi
}
suggest_runtime_library_install() {
missing_lib="$1"
if [ "$OS" != "linux" ]; then
echo "Unable to auto-suggest runtime library installation on this OS."
return
fi
package=""
if command_exists apt-get; then
case "$missing_lib" in
libdbus-1*) package="libdbus-1-3" ;;
libudev*) package="libudev1" ;;
*) package="" ;;
esac
if [ -n "$package" ]; then
cat <<EOF
Install the missing runtime library on Debian/Ubuntu:
${SUDO}apt-get update
${SUDO}apt-get install -y $package
EOF
else
cat <<EOF
Install the package that provides '$missing_lib' on Debian/Ubuntu.
You can search with:
apt-file search $missing_lib
EOF
fi
elif command_exists dnf; then
case "$missing_lib" in
libdbus-1*) package="dbus-libs" ;;
libudev*) package="systemd-libs" ;;
*) package="" ;;
esac
if [ -n "$package" ]; then
cat <<EOF
Install the missing runtime library on Fedora/RHEL:
${SUDO}dnf install -y $package
EOF
else
cat <<EOF
Install the package that provides '$missing_lib' on Fedora/RHEL.
You can search with:
dnf provides \"*/$missing_lib\"
EOF
fi
elif command_exists yum; then
case "$missing_lib" in
libdbus-1*) package="dbus-libs" ;;
libudev*) package="systemd-libs" ;;
*) package="" ;;
esac
if [ -n "$package" ]; then
cat <<EOF
Install the missing runtime library on CentOS/RHEL:
${SUDO}yum install -y $package
EOF
else
cat <<EOF
Install the package that provides '$missing_lib' on CentOS/RHEL.
You can search with:
yum provides \"*/$missing_lib\"
EOF
fi
elif command_exists pacman; then
case "$missing_lib" in
libdbus-1*) package="dbus" ;;
libudev*) package="systemd-libs" ;;
*) package="" ;;
esac
if [ -n "$package" ]; then
cat <<EOF
Install the missing runtime library on Arch:
${SUDO}pacman -S --needed $package
EOF
else
cat <<EOF
Install the package that provides '$missing_lib' on Arch.
EOF
fi
elif command_exists zypper; then
case "$missing_lib" in
libdbus-1*) package="libdbus-1-3" ;;
libudev*) package="libudev1" ;;
*) package="" ;;
esac
if [ -n "$package" ]; then
cat <<EOF
Install the missing runtime library on openSUSE:
${SUDO}zypper install -y $package
EOF
else
cat <<EOF
Install the package that provides '$missing_lib' on openSUSE.
EOF
fi
else
cat <<EOF
Install the package that provides '$missing_lib' using your distro package manager.
EOF
fi
}
has_dev_dependency() {
dep="$1"
case "$dep" in
dbus)
if command_exists pkg-config && pkg-config --exists dbus-1 2>/dev/null; then
return 0
fi
if [ -f /usr/include/dbus-1.0/dbus/dbus.h ]; then
return 0
fi
;;
udev)
if command_exists pkg-config && pkg-config --exists libudev 2>/dev/null; then
return 0
fi
if [ -f /usr/include/libudev.h ]; then
return 0
fi
;;
esac
return 1
}
attempt_runtime_deps_setup() {
if [ "$OS" != "linux" ]; then
return
fi
pkg_dbus_dev=""
pkg_udev_dev=""
manager=""
missing_pkgs=""
if command_exists apt-get; then
manager="apt-get"
pkg_dbus_dev="libdbus-1-dev"
pkg_udev_dev="libudev-dev"
elif command_exists dnf; then
manager="dnf"
pkg_dbus_dev="dbus-devel"
pkg_udev_dev="systemd-devel"
elif command_exists yum; then
manager="yum"
pkg_dbus_dev="dbus-devel"
pkg_udev_dev="systemd-devel"
elif command_exists pacman; then
manager="pacman"
pkg_dbus_dev="dbus"
pkg_udev_dev="systemd"
elif command_exists zypper; then
manager="zypper"
pkg_dbus_dev="dbus-1-devel"
pkg_udev_dev="systemd-devel"
else
echo "Warning: Could not detect a supported package manager to install development dependencies."
return
fi
if [ -n "$pkg_dbus_dev" ] && ! has_dev_dependency dbus; then
missing_pkgs="$missing_pkgs $pkg_dbus_dev"
fi
if [ -n "$pkg_udev_dev" ] && ! has_dev_dependency udev; then
missing_pkgs="$missing_pkgs $pkg_udev_dev"
fi
missing_pkgs="${missing_pkgs# }"
if [ -z "$missing_pkgs" ]; then
return
fi
echo ""
echo "Attempting development dependency setup (--install-deps): $missing_pkgs"
case "$manager" in
apt-get)
if ! run_as_root apt-get update; then
echo "Warning: apt-get update failed."
fi
# shellcheck disable=SC2086
if ! run_as_root apt-get install -y $missing_pkgs; then
echo "Warning: Failed to install development dependencies via apt-get."
fi
;;
dnf)
# shellcheck disable=SC2086
if ! run_as_root dnf install -y $missing_pkgs; then
echo "Warning: Failed to install development dependencies via dnf."
fi
;;
yum)
# shellcheck disable=SC2086
if ! run_as_root yum install -y $missing_pkgs; then
echo "Warning: Failed to install development dependencies via yum."
fi
;;
pacman)
# shellcheck disable=SC2086
if ! run_as_root pacman -S --needed --noconfirm $missing_pkgs; then
echo "Warning: Failed to install development dependencies via pacman."
fi
;;
zypper)
# shellcheck disable=SC2086
if ! run_as_root zypper install -y $missing_pkgs; then
echo "Warning: Failed to install development dependencies via zypper."
fi
;;
esac
}
suggest_rust_install() {
if [ "$OS" = "macos" ]; then
cat <<EOF
Suggested Rust setup on macOS:
brew install rustup-init
rustup-init -y
. "\$HOME/.cargo/env"
EOF
return
fi
if command_exists apt-get; then
cat <<EOF
Suggested Rust setup on Debian/Ubuntu:
${SUDO}apt-get update
${SUDO}apt-get install -y curl build-essential pkg-config libssl-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "\$HOME/.cargo/env"
EOF
elif command_exists dnf; then
cat <<EOF
Suggested Rust setup on Fedora/RHEL:
${SUDO}dnf install -y curl gcc make pkgconfig openssl-devel
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "\$HOME/.cargo/env"
EOF
elif command_exists yum; then
cat <<EOF
Suggested Rust setup on CentOS/RHEL:
${SUDO}yum install -y curl gcc make pkgconfig openssl-devel
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "\$HOME/.cargo/env"
EOF
elif command_exists pacman; then
cat <<EOF
Suggested Rust setup on Arch:
${SUDO}pacman -S --needed rustup
rustup default stable
EOF
elif command_exists zypper; then
cat <<EOF
Suggested Rust setup on openSUSE:
${SUDO}zypper install -y curl gcc make pkg-config libopenssl-devel
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "\$HOME/.cargo/env"
EOF
else
cat <<EOF
Rust is required for smart contract development.
Install rustup from https://rustup.rs, then run:
rustup default stable
EOF
fi
}
attempt_rust_setup() {
echo ""
echo "Attempting Rust setup (--install-deps)..."
if [ "$OS" = "macos" ]; then
if ! command_exists rustup && ! command_exists rustup-init; then
if command_exists brew; then
if ! brew install rustup-init; then
echo "Warning: Failed to install rustup-init with Homebrew."
fi
else
echo "Warning: Homebrew not found. Install Homebrew or rustup manually."
fi
fi
if ! command_exists rustup && command_exists rustup-init; then
if ! rustup-init -y; then
echo "Warning: rustup-init failed."
fi
fi
else
if ! command_exists rustup; then
if command_exists apt-get; then
if ! run_as_root apt-get update; then
echo "Warning: apt-get update failed."
fi
if ! run_as_root apt-get install -y curl build-essential pkg-config libssl-dev; then
echo "Warning: Failed to install Rust prerequisites via apt-get."
fi
elif command_exists dnf; then
if ! run_as_root dnf install -y curl gcc make pkgconfig openssl-devel; then
echo "Warning: Failed to install Rust prerequisites via dnf."
fi
elif command_exists yum; then
if ! run_as_root yum install -y curl gcc make pkgconfig openssl-devel; then
echo "Warning: Failed to install Rust prerequisites via yum."
fi
elif command_exists pacman; then
if ! run_as_root pacman -S --needed --noconfirm rustup; then
echo "Warning: Failed to install rustup via pacman."
fi
elif command_exists zypper; then
if ! run_as_root zypper install -y curl gcc make pkg-config libopenssl-devel; then
echo "Warning: Failed to install Rust prerequisites via zypper."
fi
fi
fi
if ! command_exists rustup; then
if command_exists curl; then
if ! curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; then
echo "Warning: rustup installer failed."
fi
else
echo "Warning: curl is required to run rustup installer."
fi
fi
fi
if [ -f "$HOME/.cargo/env" ]; then
# shellcheck disable=SC1090,SC1091
. "$HOME/.cargo/env" || true
fi
if command_exists rustup; then
if ! rustup default stable; then
echo "Warning: Failed to set default Rust toolchain to stable."
fi
if ! rustup target add wasm32v1-none; then
echo "Warning: Failed to install wasm32v1-none target."
fi
fi
}
print_contract_tooling_summary() {
if [ "$INSTALL_DEPS" = true ]; then
if ! command_exists rustup || ! command_exists cargo || ! command_exists rustc; then
attempt_rust_setup
elif command_exists rustup; then
if ! rustup target list --installed 2>/dev/null | grep -q '^wasm32v1-none$'; then
attempt_rust_setup
fi
fi
fi
echo ""
echo "Smart contract Rust environment summary:"
has_rustup="false"
has_cargo="false"
has_rustc="false"
has_wasm_target="false"
if command_exists rustup; then
has_rustup="true"
echo " [OK] rustup"
else
echo " [MISSING] rustup"
fi
if command_exists cargo; then
has_cargo="true"
echo " [OK] cargo"
else
echo " [MISSING] cargo"
fi
if command_exists rustc; then
has_rustc="true"
echo " [OK] rustc"
else
echo " [MISSING] rustc"
fi
if [ "$has_rustup" = "true" ]; then
if rustup target list --installed 2>/dev/null | grep -q '^wasm32v1-none$'; then
has_wasm_target="true"
echo " [OK] wasm32v1-none target"
else
echo " [MISSING] wasm32v1-none target"
fi
else
echo " [MISSING] wasm32v1-none target (requires rustup)"
fi
if [ "$has_rustup" = "false" ] || [ "$has_cargo" = "false" ] || [ "$has_rustc" = "false" ]; then
echo ""
if [ "$INSTALL_DEPS" != true ]; then
suggest_rust_install
echo ""
fi
echo "Then run:"
echo " rustup default stable"
echo " rustup target add wasm32v1-none"
return
fi
if [ "$has_wasm_target" = "false" ]; then
echo ""
echo "Install missing target with:"
echo " rustup target add wasm32v1-none"
return
fi
echo " Ready for smart contract builds."
}
check_runtime_libraries() {
installed_binary="$1"
if [ "$OS" != "linux" ]; then
return 0
fi
if ! command_exists ldconfig; then
return 0
fi
ldconfig_output="$(ldconfig -p 2>/dev/null)"
missing_libs=""
for lib in libdbus-1 libudev; do
if ! printf '%s\n' "$ldconfig_output" | grep -q "$lib"; then
missing_libs="$missing_libs $lib"
fi
done
missing_libs="${missing_libs# }"
if [ -z "$missing_libs" ]; then
return 0
fi
echo ""
echo "Warning: $BINARY_NAME was installed, but runtime shared libraries are missing:"
for lib in $missing_libs; do
printf ' %s\n' "$lib"
echo ""
suggest_runtime_library_install "$lib"
done
echo ""
echo "After installing the runtime dependencies, run:"
printf ' %s --version\n' "$installed_binary"
return 1
}
post_install_check() {
installed_binary="$1"
check_runtime_libraries "$installed_binary"
runtime_ok=$?
version_output=""
if version_output="$("$installed_binary" --version 2>&1)"; then
return "$runtime_ok"
fi
echo ""
echo "Warning: post-install check failed:"
printf '%s\n' "$version_output"
return 1
}
# Check if user has sudo privileges
has_sudo() {
if command -v sudo >/dev/null 2>&1; then
# Non-interactive check only; avoid prompting during auto-detection.
if sudo -n true 2>/dev/null; then
return 0
fi
fi
return 1
}
# Parse arguments and set defaults
INSTALL_DIR=""
USER_INSTALL=false
INSTALL_DEPS=false
for arg in "$@"; do
case $arg in
--user)
USER_INSTALL=true
INSTALL_DIR="${HOME}/.local/bin"
;;
--dir=*)
INSTALL_DIR="${arg#*=}"
;;
--install-deps)
INSTALL_DEPS=true
;;
--help)
echo "Stellar CLI installer"
echo ""
echo "Usage: sh install.sh [options]"
echo ""
echo "Options:"
echo " --user Install to ~/.local/bin (no sudo required)"
echo " --dir=PATH Install to custom directory"
echo " --install-deps Attempt to install missing libdbus/libudev dev dependencies and Rust toolchain"
echo " --help Show this help message"
exit 0
;;
*)
echo "Error: Unknown option: $arg"
echo "Run with --help to see available options."
exit 1
;;
esac
done
# Determine sudo prefix for suggested commands (empty if already root or sudo unavailable)
if [ "$(id -u)" = "0" ] || ! command_exists sudo; then
SUDO=""
else
SUDO="sudo "
fi
# Set default install directory if not specified
if [ -z "$INSTALL_DIR" ]; then
if [ "$(id -u)" = "0" ] || has_sudo; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
USER_INSTALL=true
echo "Note: No sudo privileges detected, installing to $INSTALL_DIR"
fi
fi
# Detect OS
OS="$(uname -s)"
case "$OS" in
Linux*)
OS="linux"
;;
Darwin*)
OS="macos"
;;
*)
echo "Error: Unsupported operating system: $OS"
exit 1
;;
esac
# Validate basic installer dependencies before other checks use them
check_dependencies
# Detect architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64)
ARCH="x86_64"
;;
aarch64|arm64)
ARCH="aarch64"
;;
*)
echo "Error: Unsupported architecture: $ARCH"
exit 1
;;
esac
# Construct target triple
if [ "$OS" = "linux" ]; then
LIBC="$(detect_linux_libc)"
if [ "$LIBC" = "musl" ]; then
echo "Error: Detected Linux distro '$(detect_linux_distro)' using musl libc."
echo "This installer downloads a prebuilt Stellar CLI release that targets glibc (GNU/Linux) and is not supported on musl systems (e.g. Alpine)."
if [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
echo ""
echo "Note: Found an existing '$BINARY_NAME' binary at ${INSTALL_DIR}/${BINARY_NAME}."
echo "This binary is built for glibc and will not run correctly on musl-based systems."
fi
echo ""
echo "Recommended next steps:"
echo " 1) Use a glibc-based image (Debian/Ubuntu/Fedora)."
echo " Example: docker run -it --rm debian:bookworm-slim"
echo " 2) If you must stay on Alpine, build stellar-cli from source on Alpine."
exit 1
fi
TARGET="${ARCH}-unknown-linux-gnu"
elif [ "$OS" = "macos" ]; then
TARGET="${ARCH}-apple-darwin"
fi
echo "Detected platform: $OS ($TARGET)"
# Create temporary directory (used for both release response and binary extraction)
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM HUP
# Get latest release version
echo "Fetching latest release..."
RELEASE_RESPONSE_FILE="$TMP_DIR/release.json"
if ! RELEASE_HTTP_STATUS="$(curl -sSL -o "$RELEASE_RESPONSE_FILE" -w "%{http_code}" "https://api.github.com/repos/${REPO}/releases/latest")"; then
echo "Error: Could not reach GitHub API to fetch latest release"
exit 1
fi
if [ "$RELEASE_HTTP_STATUS" != "200" ]; then
if [ "$RELEASE_HTTP_STATUS" = "403" ] && grep -qi "rate limit" "$RELEASE_RESPONSE_FILE"; then
echo "Error: GitHub API rate limit exceeded while fetching latest release."
echo "Try again later."
else
echo "Error: Could not fetch latest release (GitHub API HTTP $RELEASE_HTTP_STATUS)"
fi
exit 1
fi
LATEST_RELEASE="$(grep '"tag_name":' "$RELEASE_RESPONSE_FILE" | sed -E 's/.*"([^"]+)".*/\1/')"
if [ -z "$LATEST_RELEASE" ]; then
echo "Error: Could not fetch latest release"
exit 1
fi
VERSION="${LATEST_RELEASE#v}"
echo "Latest version: $VERSION"
# Construct download URL
ARCHIVE_NAME="${REPO##*/}-${VERSION}-${TARGET}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${LATEST_RELEASE}/${ARCHIVE_NAME}"
echo "Downloading from: $DOWNLOAD_URL"
# Download and extract
cd "$TMP_DIR"
if ! curl -fsSL "$DOWNLOAD_URL" -o "$ARCHIVE_NAME"; then
echo "Error: Failed to download $DOWNLOAD_URL"
exit 1
fi
echo "Extracting archive..."
tar xzf "$ARCHIVE_NAME"
# Create install directory if it doesn't exist
if [ ! -d "$INSTALL_DIR" ]; then
echo "Creating install directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
fi
# Install binary
echo "Installing $BINARY_NAME to $INSTALL_DIR..."
if [ "$USER_INSTALL" = true ] || [ -w "$INSTALL_DIR" ]; then
mv "$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
sudo mv "$BINARY_NAME" "$INSTALL_DIR/"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
if [ "$INSTALL_DEPS" = true ]; then
attempt_runtime_deps_setup
fi
POST_INSTALL_OK=true
if ! post_install_check "$INSTALL_DIR/$BINARY_NAME"; then
POST_INSTALL_OK=false
fi
echo ""
if [ "$POST_INSTALL_OK" = true ]; then
echo "[OK] Stellar CLI installed successfully!"
else
echo "Warning: Stellar CLI binary was installed, but failed post-install verification."
fi
echo ""
echo "Location: $INSTALL_DIR/$BINARY_NAME"
echo "Version: $VERSION"
echo ""
# Check if install directory is in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*)
echo "Run '$BINARY_NAME --version' to verify the installation."
;;
*)
echo "Note: $INSTALL_DIR is not in your PATH."
echo "Add it to your PATH by adding this line to your shell profile:"
echo ""
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
echo ""
;;
esac
print_contract_tooling_summary
if [ "$POST_INSTALL_OK" != true ]; then
exit 1
fi