Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·697 lines (623 loc) · 23.4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·697 lines (623 loc) · 23.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
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
#!/usr/bin/env bash
set -euo pipefail
APP_NAME="MovieBox-Tui"
BIN_NAME="moviebox-tui"
REPO="mesamirh/MovieBox-Tui"
DEFAULT_INSTALL_DIR="$HOME/.local/bin"
VERSION=""
CUSTOM_DIR=""
FORCE=0
DRY_RUN=0
NO_MODIFY_PATH=0
UNINSTALL=0
while [ $# -gt 0 ]; do
case "$1" in
--version=*|-v=*)
VERSION="${1#*=}"
shift
;;
--version|-v)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
printf "error: --version requires a release tag argument.\n" >&2
exit 1
fi
VERSION="${2:-}"
shift 2
;;
--dir=*)
CUSTOM_DIR="${1#*=}"
shift
;;
--dir)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
printf "error: --dir requires a path argument.\n" >&2
exit 1
fi
CUSTOM_DIR="${2:-}"
shift 2
;;
--force|-f)
FORCE=1
shift
;;
--dry-run)
DRY_RUN=1
shift
;;
--no-modify-path)
NO_MODIFY_PATH=1
shift
;;
--uninstall)
UNINSTALL=1
shift
;;
--help|-h)
cat << 'EOF'
MovieBox-TUI Installer
USAGE:
curl -fsSL https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.sh | bash -s -- [OPTIONS]
./install.sh [OPTIONS]
OPTIONS:
-v, --version <tag> Install a specific version (e.g. v0.1.14)
--dir <path> Install binary to a custom directory
-f, --force Reinstall even if already at the latest version
--dry-run Perform preflight checks without writing files
--no-modify-path Do not modify shell profile configuration
--uninstall Uninstall MovieBox-TUI from your system
-h, --help Show this help message
EOF
exit 0
;;
*)
printf "warning: ignoring unknown argument: %s\n" "$1" >&2
shift
;;
esac
done
while [ -n "$CUSTOM_DIR" ] && [ "${CUSTOM_DIR%/}" != "$CUSTOM_DIR" ]; do
CUSTOM_DIR="${CUSTOM_DIR%/}"
done
IS_TTY=0
if [ -t 1 ]; then
IS_TTY=1
fi
IS_COLOR=0
if [ -z "${NO_COLOR:-}" ] && [ "${TERM:-}" != "dumb" ] && [ -t 1 ]; then
IS_COLOR=1
fi
if [ "$IS_COLOR" -eq 1 ]; then
C_RESET="\033[0m"
C_BOLD="\033[1m"
C_DIM="\033[2m"
if [ "${COLORTERM:-}" = "truecolor" ] || [ "${COLORTERM:-}" = "24bit" ] || [ -n "${WT_SESSION:-}" ] || [ "${TERM_PROGRAM:-}" = "Apple_Terminal" ] || [ "${TERM_PROGRAM:-}" = "iTerm.app" ] || [ "${TERM_PROGRAM:-}" = "ghostty" ] || [ "${TERM_PROGRAM:-}" = "WezTerm" ] || [ "${TERM_PROGRAM:-}" = "warp" ]; then
C_MAUVE="\033[38;2;203;166;247m"
C_BLUE="\033[38;2;137;180;250m"
C_SAPPHIRE="\033[38;2;116;199;236m"
C_LAVENDER="\033[38;2;180;190;254m"
C_TEAL="\033[38;2;148;226;213m"
C_GREEN="\033[38;2;166;227;161m"
C_YELLOW="\033[38;2;249;226;175m"
C_RED="\033[38;2;243;139;168m"
C_TEXT="\033[38;2;205;214;244m"
C_SUBTEXT="\033[38;2;166;173;200m"
C_MUTED="\033[38;2;108;112;134m"
else
C_MAUVE="\033[35m"
C_BLUE="\033[34m"
C_SAPPHIRE="\033[36m"
C_LAVENDER="\033[35m"
C_TEAL="\033[36m"
C_GREEN="\033[32m"
C_YELLOW="\033[33m"
C_RED="\033[31m"
C_TEXT="\033[37m"
C_SUBTEXT="\033[37m"
C_MUTED="\033[90m"
fi
CURSOR_HIDE="\033[?25l"
CURSOR_SHOW="\033[?25h"
else
C_RESET=""
C_BOLD=""
C_DIM=""
C_MAUVE=""
C_BLUE=""
C_SAPPHIRE=""
C_LAVENDER=""
C_TEAL=""
C_GREEN=""
C_YELLOW=""
C_RED=""
C_TEXT=""
C_SUBTEXT=""
C_MUTED=""
CURSOR_HIDE=""
CURSOR_SHOW=""
fi
cleanup() {
printf "%b" "$CURSOR_SHOW" 2>/dev/null || true
if [ -n "${TMP_VER_FILE:-}" ] && [ -f "$TMP_VER_FILE" ]; then
rm -f "$TMP_VER_FILE"
fi
if [ -n "${TMP_DIR:-}" ] && [ -d "$TMP_DIR" ]; then
rm -rf "$TMP_DIR"
fi
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
log_step() {
printf " %b%s%b %b%s%b\n" "$C_BLUE" "→" "$C_RESET" "$C_TEXT" "$1" "$C_RESET"
}
log_success() {
printf " %b%s%b %b%s%b\n" "$C_GREEN" "✔" "$C_RESET" "$C_TEXT" "$1" "$C_RESET"
}
log_warn() {
printf " %b%s%b %b%s%b\n" "$C_YELLOW" "⚠" "$C_RESET" "$C_TEXT" "$1" "$C_RESET"
}
log_error() {
printf " %b%s%b %b%s%b\n" "$C_RED" "✖" "$C_RESET" "$C_TEXT" "$1" "$C_RESET" >&2
}
clear_screen() {
if [ "$IS_TTY" -eq 1 ] && [ "${TERM:-}" != "dumb" ]; then
clear 2>/dev/null || printf "\033[2J\033[3J\033[H"
fi
}
get_terminal_cols() {
local cols=""
if [ -n "${COLUMNS:-}" ] && [[ "$COLUMNS" =~ ^[0-9]+$ ]] && [ "$COLUMNS" -gt 0 ]; then
cols="$COLUMNS"
elif [ -t 1 ] || [ -t 2 ]; then
cols=$(tput cols 2>/dev/null || true)
if [ -z "$cols" ] || [ "$cols" -le 0 ] 2>/dev/null; then
cols=$(stty size 2>/dev/null | awk '{print $2}')
fi
fi
if [ -z "$cols" ] || [ "$cols" -le 0 ] 2>/dev/null; then
cols=80
fi
printf "%s" "$cols"
}
print_header() {
clear_screen
local cols
cols=$(get_terminal_cols)
local lines=()
local banner_width=0
if [ "$cols" -ge 76 ]; then
banner_width=72
lines=(
"███╗ ███╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗"
"████╗ ████║ ██╔═══██╗ ██║ ██║ ██║ ██╔════╝ ██╔══██╗ ██╔═══██╗ ╚██╗██╔╝"
"██╔████╔██║ ██║ ██║ ██║ ██║ ██║ █████╗ ██████╔╝ ██║ ██║ ╚███╔╝ "
"██║╚██╔╝██║ ██║ ██║ ╚██╗ ██╔╝ ██║ ██╔══╝ ██╔══██╗ ██║ ██║ ██╔██╗ "
"██║ ╚═╝ ██║ ╚██████╔╝ ╚████╔╝ ██║ ███████╗ ██████╔╝ ╚██████╔╝ ██╔╝ ██╗"
"╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝"
)
elif [ "$cols" -ge 36 ]; then
banner_width=31
lines=(
"█▀▄▀█ █▀█ █ █ █ █▀▀ █▀▄ █▀█ ▀▄▀"
"█ ▀ █ █▄█ ▀▄▀ █ ██▄ █▄▀ █▄█ █ █"
)
else
banner_width=12
lines=(
"MovieBox-TUI"
)
fi
local banner_pad=0
if [ "$cols" -gt "$banner_width" ]; then
banner_pad=$(( (cols - banner_width) / 2 ))
fi
local sub="Official Installer"
local sub_len=${#sub}
local sub_pad=0
if [ "$cols" -gt "$sub_len" ]; then
sub_pad=$(( (cols - sub_len) / 2 ))
fi
if [ "$IS_COLOR" -eq 1 ] && [ "$IS_TTY" -eq 1 ]; then
printf "%b\n" "$CURSOR_HIDE"
printf "%b%b" "$C_BOLD" "$C_MAUVE"
for line in "${lines[@]}"; do
if [ "$banner_pad" -gt 0 ]; then
printf "%*s%s\n" "$banner_pad" "" "$line"
else
printf "%s\n" "$line"
fi
sleep 0.02
done
if [ "$sub_pad" -gt 0 ]; then
printf "%*s%b%b%s%b%b\n\n" "$sub_pad" "" "$C_SAPPHIRE" "$C_BOLD" "$sub" "$C_RESET" "$CURSOR_SHOW"
else
printf "%b%b%s%b%b\n\n" "$C_SAPPHIRE" "$C_BOLD" "$sub" "$C_RESET" "$CURSOR_SHOW"
fi
else
for line in "${lines[@]}"; do
if [ "$banner_pad" -gt 0 ]; then
printf "%*s%s\n" "$banner_pad" "" "$line"
else
printf "%s\n" "$line"
fi
done
if [ "$sub_pad" -gt 0 ]; then
printf "%*s%s\n\n" "$sub_pad" "" "$sub"
else
printf "%s\n\n" "$sub"
fi
fi
}
run_spinner() {
local message="$1"
shift
local cmd=("$@")
if [ "$IS_TTY" -ne 1 ] || [ "$IS_COLOR" -ne 1 ]; then
log_step "$message..."
if ! "${cmd[@]}"; then
log_error "$message failed."
return 1
fi
return 0
fi
local spin_chars=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏")
local spin_count=${#spin_chars[@]}
local spin_idx=0
local tmp_out
tmp_out=$(mktemp)
printf "%b" "$CURSOR_HIDE"
"${cmd[@]}" > "$tmp_out" 2>&1 &
local pid=$!
while kill -0 "$pid" 2>/dev/null; do
local frame="${spin_chars[$spin_idx]}"
printf "\r\033[K %b%s%b %b%s...%b" "$C_SAPPHIRE" "$frame" "$C_RESET" "$C_TEXT" "$message" "$C_RESET"
spin_idx=$(( (spin_idx + 1) % spin_count ))
sleep 0.08
done
wait "$pid"
local exit_code=$?
printf "%b" "$CURSOR_SHOW"
if [ "$exit_code" -eq 0 ]; then
printf "\r\033[K"
rm -f "$tmp_out"
return 0
else
printf "\r\033[K"
log_error "$message failed:"
cat "$tmp_out" >&2
rm -f "$tmp_out"
return "$exit_code"
fi
}
do_uninstall() {
print_header
log_step "Uninstalling $APP_NAME..."
local found=0
local target_paths=(
"$HOME/.local/bin/$BIN_NAME"
"/usr/local/bin/$BIN_NAME"
)
if [ -n "${PREFIX:-}" ]; then
target_paths+=("$PREFIX/bin/$BIN_NAME")
fi
if command -v "$BIN_NAME" >/dev/null 2>&1; then
local current_path
current_path=$(command -v "$BIN_NAME")
target_paths+=("$current_path")
fi
for path in "${target_paths[@]}"; do
if [ -n "$path" ] && [ -f "$path" ]; then
if [ -w "$path" ] || [ -w "$(dirname "$path")" ]; then
rm -f "$path"
log_success "Removed $path"
found=1
elif command -v sudo >/dev/null 2>&1; then
sudo rm -f "$path"
log_success "Removed $path (with sudo)"
found=1
fi
fi
done
if [ "$found" -eq 1 ]; then
log_success "$APP_NAME was successfully uninstalled."
else
log_warn "No installed binary of $BIN_NAME was found."
fi
exit 0
}
if [ "$UNINSTALL" -eq 1 ]; then
do_uninstall
fi
print_header
command -v curl >/dev/null 2>&1 || { log_error "curl is required but not installed. Please install curl."; exit 1; }
command -v tar >/dev/null 2>&1 || { log_error "tar is required but not installed. Please install tar."; exit 1; }
OS="$(uname -s)"
ARCH="$(uname -m)"
IS_TERMUX=0
if [ -n "${PREFIX:-}" ] && [[ "$PREFIX" == *com.termux* ]]; then
IS_TERMUX=1
fi
if [ "$IS_TERMUX" -eq 1 ]; then
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
FILE="MovieBox_Android_arm64.tar.gz"
PLATFORM_NAME="Android Termux (arm64)"
else
log_error "Unsupported Termux architecture ($ARCH). Only arm64/aarch64 is hosted. Use 'cargo install moviebox-tui'."
exit 1
fi
elif [ "$OS" = "Darwin" ]; then
FILE="MovieBox_macOS_Universal.tar.gz"
PLATFORM_NAME="macOS (Universal)"
elif [ "$OS" = "Linux" ]; then
if [ "$ARCH" = "x86_64" ]; then
FILE="MovieBox_Linux_x64.tar.gz"
PLATFORM_NAME="Linux (x86_64)"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
if command -v getconf >/dev/null 2>&1 && [ "$(getconf LONG_BIT 2>/dev/null)" = "32" ]; then
log_error "Detected 32-bit userland on 64-bit ARM hardware ($ARCH kernel with 32-bit armhf OS)."
log_error "Prebuilt Linux ARM64 binaries require 64-bit userland (aarch64)."
printf "\n %bℹ%b To run on 32-bit Raspberry Pi OS, compile natively via cargo:\n" "$C_SAPPHIRE" "$C_RESET" >&2
printf " %bsudo apt update && sudo apt install -y pkg-config libssl-dev%b\n" "$C_BOLD" "$C_RESET" >&2
printf " %bcargo install moviebox-tui --locked%b\n\n" "$C_BOLD" "$C_RESET" >&2
exit 1
fi
FILE="MovieBox_Linux_arm64.tar.gz"
PLATFORM_NAME="Linux (arm64)"
else
log_error "Unsupported Linux architecture ($ARCH). Only x86_64 and arm64 are supported."
exit 1
fi
elif case "$OS" in MINGW*|MSYS*|CYGWIN*) true ;; *) false ;; esac; then
log_error "Windows environment detected ($OS)."
printf "\n %bℹ%b Please use the official Windows PowerShell installer:\n" "$C_SAPPHIRE" "$C_RESET" >&2
printf " %birm https://raw.githubusercontent.com/%s/main/install.ps1 | iex%b\n\n" "$C_BOLD" "$REPO" "$C_RESET" >&2
exit 1
else
log_error "Unsupported Operating System ($OS)."
exit 1
fi
TMP_VER_FILE=$(mktemp)
resolve_version() {
if [ -n "$VERSION" ]; then
printf "%s" "$VERSION" > "$TMP_VER_FILE"
return 0
fi
if [ -n "${MOVIEBOX_RELEASE_URL:-}" ]; then
printf "%s" "local-test" > "$TMP_VER_FILE"
return 0
fi
local release_header
release_header=$(curl -fsSI "https://github.com/$REPO/releases/latest" 2>/dev/null || true)
local tag=""
if [ -n "$release_header" ]; then
tag=$(printf "%s" "$release_header" | grep -i '^location:' | awk -F '/' '{print $NF}' | tr -d '\r\n')
fi
if [ -z "$tag" ]; then
tag=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" 2>/dev/null | grep '"tag_name":' | head -1 | awk -F '"' '{print $4}' || true)
fi
if [ -z "$tag" ]; then
log_error "Could not resolve latest release version from GitHub."
return 1
fi
printf "%s" "$tag" > "$TMP_VER_FILE"
}
run_spinner "[1/4] Checking environment & resolving version" resolve_version || exit 1
TARGET_VERSION=$(cat "$TMP_VER_FILE" 2>/dev/null || true)
rm -f "$TMP_VER_FILE"
TMP_VER_FILE=""
if [ -z "$TARGET_VERSION" ]; then
log_error "Could not resolve release version."
exit 1
fi
log_success "[1/4] Environment ready ($PLATFORM_NAME • $TARGET_VERSION)"
if [ -n "$CUSTOM_DIR" ]; then
INSTALL_DIR="$CUSTOM_DIR"
elif [ "$IS_TERMUX" -eq 1 ]; then
INSTALL_DIR="$PREFIX/bin"
else
INSTALL_DIR="$DEFAULT_INSTALL_DIR"
fi
APP_PATH="$INSTALL_DIR/$BIN_NAME"
EXISTING_BIN=$(command -v "$BIN_NAME" 2>/dev/null || true)
if [ -n "$EXISTING_BIN" ] && [ -x "$EXISTING_BIN" ]; then
CURRENT_VERSION=$("$EXISTING_BIN" --version 2>/dev/null | awk '{print $2}' || true)
CURRENT_VERSION=${CURRENT_VERSION:-unknown}
if [ "v$CURRENT_VERSION" = "$TARGET_VERSION" ] && [ "$FORCE" -eq 0 ]; then
if [ "$IS_TTY" -eq 1 ] && [ "$DRY_RUN" -eq 0 ]; then
printf "\n %b%s%b %b%s%b\n" "$C_YELLOW" "ℹ" "$C_RESET" "$C_TEXT" "MovieBox-TUI $TARGET_VERSION is already installed at $EXISTING_BIN." "$C_RESET"
printf " Choose an action: [1] Reinstall [2] Uninstall [3] Exit: "
if [ -e /dev/tty ]; then
read -r user_choice </dev/tty 2>/dev/null || user_choice="3"
else
read -r user_choice || user_choice="3"
fi
case "$user_choice" in
1)
log_step "Proceeding with reinstall..."
;;
2)
do_uninstall
;;
*)
log_success "No changes made. Exiting."
exit 0
;;
esac
else
log_success "MovieBox-TUI $TARGET_VERSION is already installed. Use --force to reinstall."
exit 0
fi
fi
fi
if [ "$DRY_RUN" -eq 1 ]; then
log_success "[Dry Run] Target package: $FILE"
log_success "[Dry Run] Target install directory: $APP_PATH"
log_success "[Dry Run] All preflight checks passed."
exit 0
fi
TMP_DIR=$(mktemp -d)
if [ -n "${MOVIEBOX_RELEASE_URL:-}" ]; then
URL="${MOVIEBOX_RELEASE_URL%/}/$FILE"
CHECKSUM_URL="${MOVIEBOX_RELEASE_URL%/}/SHA256SUMS"
else
URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/$FILE"
CHECKSUM_URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/SHA256SUMS"
fi
download_files() {
if ! curl -fsSL "$URL" -o "$TMP_DIR/$FILE"; then
if [ "$IS_TERMUX" -eq 1 ]; then
printf "\n" >&2
log_error "Failed to download $FILE."
printf " %bℹ%b Precompiled native Android binaries are hosted starting from v0.1.17+.\n" "$C_SAPPHIRE" "$C_RESET" >&2
printf " To install from source on Termux:\n" >&2
printf " %bpkg install -y rust clang && cargo install moviebox-tui --locked%b\n\n" "$C_BOLD" "$C_RESET" >&2
fi
return 1
fi
curl -fsSL "$CHECKSUM_URL" -o "$TMP_DIR/SHA256SUMS"
}
run_spinner "[2/4] Downloading $FILE" download_files || exit 1
log_success "[2/4] Downloaded $FILE"
verify_checksum() {
local expected_sha
expected_sha=$(awk -v file="$FILE" '{gsub(/^\*/, "", $2); if ($2 == file) print $1}' "$TMP_DIR/SHA256SUMS")
if [ -z "$expected_sha" ]; then
return 1
fi
local actual_sha=""
if command -v sha256sum >/dev/null 2>&1; then
actual_sha=$(sha256sum "$TMP_DIR/$FILE" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual_sha=$(shasum -a 256 "$TMP_DIR/$FILE" | awk '{print $1}')
elif command -v openssl >/dev/null 2>&1; then
actual_sha=$(openssl dgst -sha256 "$TMP_DIR/$FILE" | awk '{print $NF}')
else
return 1
fi
[ "$actual_sha" = "$expected_sha" ]
}
run_spinner "[3/4] Verifying SHA256 checksum" verify_checksum || exit 1
log_success "[3/4] Cryptographic checksum verified"
mkdir -p "$INSTALL_DIR" 2>/dev/null || true
if [ ! -w "$INSTALL_DIR" ] && [ ! -w "$(dirname "$INSTALL_DIR")" ]; then
INSTALL_DIR="$HOME/.local/bin"
APP_PATH="$INSTALL_DIR/$BIN_NAME"
mkdir -p "$INSTALL_DIR" 2>/dev/null || true
fi
install_binary() {
tar -xzf "$TMP_DIR/$FILE" -C "$TMP_DIR"
if [ ! -f "$TMP_DIR/$BIN_NAME" ]; then
return 1
fi
rm -f "$APP_PATH"
cp "$TMP_DIR/$BIN_NAME" "$APP_PATH"
chmod 755 "$APP_PATH"
}
run_spinner "[4/4] Installing binary to $INSTALL_DIR" install_binary || exit 1
log_success "[4/4] Binary installed to $APP_PATH"
if [ "$DRY_RUN" -eq 0 ]; then
set +e
smoke_output=$("$APP_PATH" --version 2>&1)
smoke_status=$?
set -e
if [ "$smoke_status" -ne 0 ]; then
log_error "Installed binary failed execution smoke test ($APP_PATH, exit code $smoke_status):"
if [ -n "$smoke_output" ]; then
printf " %s\n" "$smoke_output" >&2
else
printf " (Process terminated with exit status %d without output)\n" "$smoke_status" >&2
fi
if [ "$IS_TERMUX" -eq 1 ]; then
printf "\n %bℹ%b If Termux rejects the binary, install via cargo:\n" "$C_SAPPHIRE" "$C_RESET" >&2
printf " %bpkg install -y rust clang && cargo install moviebox-tui --locked%b\n\n" "$C_BOLD" "$C_RESET" >&2
elif [ "$OS" = "Linux" ] && { [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; }; then
printf "\n %bℹ%b If your Linux distribution kernel or environment rejects the binary, install via cargo:\n" "$C_SAPPHIRE" "$C_RESET" >&2
printf " %bcargo install moviebox-tui --locked%b\n\n" "$C_BOLD" "$C_RESET" >&2
fi
exit 1
fi
fi
SHELL_MODIFIED=""
if [ "$NO_MODIFY_PATH" -eq 0 ]; then
if ! echo "$PATH" | tr ':' '\n' | grep -Fqx "$INSTALL_DIR"; then
CURRENT_SHELL=$(basename "${SHELL:-bash}")
RC_FILE=""
case "$CURRENT_SHELL" in
zsh)
RC_FILE="$HOME/.zshrc"
;;
bash)
if [ -f "$HOME/.bashrc" ]; then
RC_FILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
RC_FILE="$HOME/.bash_profile"
else
RC_FILE="$HOME/.bashrc"
fi
;;
fish)
RC_FILE="$HOME/.config/fish/config.fish"
;;
esac
if [ -n "$RC_FILE" ]; then
mkdir -p "$(dirname "$RC_FILE")"
if [ -f "$RC_FILE" ] && grep -Fq -- "$INSTALL_DIR" "$RC_FILE"; then
:
else
if [ "$CURRENT_SHELL" = "fish" ]; then
printf "\nfish_add_path %s\n" "$INSTALL_DIR" >> "$RC_FILE"
else
printf "\nexport PATH=\"%s:\$PATH\"\n" "$INSTALL_DIR" >> "$RC_FILE"
fi
SHELL_MODIFIED="$RC_FILE"
fi
fi
fi
fi
PLAYER_DETECTED=""
if [ "$OS" = "Darwin" ]; then
if command -v iina >/dev/null 2>&1 || command -v iina-cli >/dev/null 2>&1 || [ -d "/Applications/IINA.app" ] || [ -d "$HOME/Applications/IINA.app" ]; then
PLAYER_DETECTED="IINA"
elif command -v mpv >/dev/null 2>&1 || [ -d "/Applications/mpv.app" ] || [ -d "$HOME/Applications/mpv.app" ]; then
PLAYER_DETECTED="mpv"
elif command -v vlc >/dev/null 2>&1 || [ -d "/Applications/VLC.app" ] || [ -d "$HOME/Applications/VLC.app" ]; then
PLAYER_DETECTED="VLC"
fi
else
if command -v mpv >/dev/null 2>&1 || [ -f "$HOME/.local/share/flatpak/exports/bin/io.mpv.Mpv" ] || [ -f "/var/lib/flatpak/exports/bin/io.mpv.Mpv" ]; then
PLAYER_DETECTED="mpv"
elif command -v vlc >/dev/null 2>&1 || [ -f "$HOME/.local/share/flatpak/exports/bin/org.videolan.VLC" ] || [ -f "/var/lib/flatpak/exports/bin/org.videolan.VLC" ]; then
PLAYER_DETECTED="VLC"
elif command -v termux-open >/dev/null 2>&1 || command -v termux-am >/dev/null 2>&1; then
PLAYER_DETECTED="Android Player (termux intent)"
fi
fi
printf "\n"
printf " %b✔ MovieBox-Tui %s successfully installed!%b\n\n" "$C_GREEN" "$TARGET_VERSION" "$C_RESET"
printf " %b•%b %bBinary:%b %b%s%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_TEXT" "$APP_PATH" "$C_RESET"
if [ -n "$PLAYER_DETECTED" ]; then
printf " %b•%b %bPlayer:%b %b%s (ready)%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_GREEN" "$PLAYER_DETECTED" "$C_RESET"
elif [ "$IS_TERMUX" -eq 1 ]; then
printf " %b•%b %bPlayer:%b %bNone detected (run 'pkg install -y termux-tools')%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_SAPPHIRE" "$C_RESET"
else
printf " %b•%b %bPlayer:%b %bNone detected (mpv, VLC, or IINA recommended)%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_SAPPHIRE" "$C_RESET"
fi
if [ -n "$SHELL_MODIFIED" ]; then
printf " %b•%b %bShell:%b %bPATH added to %s%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_LAVENDER" "$SHELL_MODIFIED" "$C_RESET"
fi
printf "\n"
printf " %bTo start streaming:%b\n" "$C_TEXT" "$C_RESET"
printf " %b$ moviebox-tui%b\n\n" "$C_GREEN" "$C_RESET"
if [ -z "$PLAYER_DETECTED" ]; then
if [ "$IS_TERMUX" -eq 1 ]; then
printf " %bℹ%b Note: Run %b'pkg install -y termux-tools'%b to enable video playback on Termux.\n" "$C_SAPPHIRE" "$C_RESET" "$C_BOLD" "$C_RESET"
printf " Streams play via external Android players (VLC, MX Player, or Just Player).\n\n"
else
printf " %bℹ%b Note: A media player (mpv, VLC, or IINA) is recommended for video playback.\n\n" "$C_SAPPHIRE" "$C_RESET"
fi
elif [ "$IS_TERMUX" -eq 1 ]; then
printf " %bℹ%b Streams will open in your default Android video player (VLC, MX Player, or Just Player).\n\n" "$C_SAPPHIRE" "$C_RESET"
fi
if [ -n "$SHELL_MODIFIED" ]; then
printf " %bℹ%b Run %b'source %s'%b or restart your terminal to reload PATH.\n\n" "$C_SAPPHIRE" "$C_RESET" "$C_BOLD" "$SHELL_MODIFIED" "$C_RESET"
fi