Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
feat(install): re-architect install.sh and install.ps1 with official block art and multi-tier animations
Samir Hossainsd9102b231053
diff --git a/README.md b/README.mdindex a512c63..83473e9 100644--- a/README.md+++ b/README.md@@ -82,7 +82,7 @@ The formula selects the correct macOS, Linux x86_64, or Linux ARM64 release.curl -fsSL https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.sh | bash```-The script detects OS and CPU architecture, then installs to `/usr/local/bin`. Without write access or `sudo`, it uses `~/.local/bin`.+The script features multi-tier animations, automatic SHA256 checksum verification, media player detection, and non-destructive shell PATH configuration. Supports `--version <tag>`, `--dir <path>`, `--force`, and `--uninstall`.### Windows@@ -92,7 +92,7 @@ Works in PowerShell or Command Prompt (cmd):powershell -Command "irm https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.ps1 | iex"```-The installer selects x86_64 or ARM64, installs under `%LOCALAPPDATA%\MovieBox-Tui`, and adds that directory to the user PATH. Open a new terminal after first installation.+The installer selects x86_64 or ARM64, verifies checksums, installs under `%LOCALAPPDATA%\Programs\MovieBox-Tui\bin`, and automatically adds the directory to your user PATH. Supports `-Version <tag>`, `-InstallDir <path>`, `-Force`, and `-Uninstall`.### Android (Termux)diff --git a/install.ps1 b/install.ps1index 4e6ac62..b6d5a08 100644--- a/install.ps1+++ b/install.ps1@@ -1,116 +1,255 @@+param(+ [string]$Version = "",+ [string]$InstallDir = "",+ [switch]$Force,+ [switch]$DryRun,+ [switch]$NoModifyPath,+ [switch]$Uninstall,+ [switch]$Help+)+$ErrorActionPreference = 'Stop'Set-StrictMode -Version Latest-function Write-Info { param([string]$Message) Write-Host "$Message" -ForegroundColor Cyan }-function Write-Success { param([string]$Message) Write-Host "$Message" -ForegroundColor Green }-function Write-Warn { param([string]$Message) Write-Host "WARNING: $Message" -ForegroundColor Yellow }-function Write-Err { param([string]$Message) Write-Host "ERROR: $Message" -ForegroundColor Red; exit 1 }+$AppName = "MovieBox-Tui"+$BinName = "moviebox-tui.exe"+$Repo = "mesamirh/MovieBox-Tui"+$DefaultInstallDir = Join-Path $env:LOCALAPPDATA "Programs\MovieBox-Tui\bin"-$InstallDir = "$env:LOCALAPPDATA\MovieBox-Tui"-$ExePath = "$InstallDir\moviebox-tui.exe"+if ($Help) {+ Write-Host @"+MovieBox-TUI Installer (Windows PowerShell)-Write-Info "Fetching latest version information..."-try {- $Request = [System.Net.WebRequest]::Create("https://github.com/mesamirh/MovieBox-Tui/releases/latest")- $Request.AllowAutoRedirect = $false- $Response = $Request.GetResponse()- $Location = $Response.Headers["Location"]- $Version = $Location.Split('/')[-1]- $Response.Close()- if (-not $Version) { throw "Version not found from redirect." }-} catch {- Write-Err "Failed to fetch latest version from GitHub API. Please check your internet connection."+USAGE:+ irm https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.ps1 | iex+ .\install.ps1 [OPTIONS]++OPTIONS:+ -Version <tag> Install a specific version (e.g. v0.1.11)+ -InstallDir <path> Install binary to a custom directory+ -Force Reinstall even if already at the latest version+ -DryRun Perform preflight checks without writing files+ -NoModifyPath Do not modify User PATH environment variable+ -Uninstall Uninstall MovieBox-TUI from your system+ -Help Show this help message+"@+ exit 0}-$IsUpdate = $false-$CurrentVersion = "unknown"-if (Test-Path $ExePath) {- try {- $CurrentVersionOutput = (& $ExePath --version 2>&1 | Out-String)- if ($CurrentVersionOutput -match "moviebox-tui\s+([\d\.]+)") {- $CurrentVersion = $matches[1]- if ("v$CurrentVersion" -eq $Version) {- Write-Success "You already have the latest version ($Version) installed."- exit 0+function Write-Step { param([string]$Message) Write-Host " → $Message" -ForegroundColor Cyan }+function Write-Success { param([string]$Message) Write-Host " ✔ $Message" -ForegroundColor Green }+function Write-Warn { param([string]$Message) Write-Host " ⚠ $Message" -ForegroundColor Yellow }+function Write-Err { param([string]$Message) Write-Host " ✖ $Message" -ForegroundColor Red; exit 1 }++function Print-Header {+ $Header = @"+███╗ ███╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗+████╗ ████║ ██╔═══██╗ ██║ ██║ ██║ ██╔════╝ ██╔══██╗ ██╔═══██╗ ╚██╗██╔╝+██╔████╔██║ ██║ ██║ ██║ ██║ ██║ █████╗ ██████╔╝ ██║ ██║ ╚███╔╝+██║╚██╔╝██║ ██║ ██║ ╚██╗ ██╔╝ ██║ ██╔══╝ ██╔══██╗ ██║ ██║ ██╔██╗+██║ ╚═╝ ██║ ╚██████╔╝ ╚████╔╝ ██║ ███████╗ ██████╔╝ ╚██████╔╝ ██╔╝ ██╗+╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝+ MovieBox-Tui Installer+"@+ Write-Host $Header -ForegroundColor Cyan+ Write-Host ""+}++function Do-Uninstall {+ Print-Header+ Write-Step "Uninstalling $AppName..."++ $Found = $false+ $TargetDirs = @(+ $DefaultInstallDir,+ "$env:LOCALAPPDATA\MovieBox-Tui"+ )++ foreach ($Dir in $TargetDirs) {+ $Exe = Join-Path $Dir $BinName+ if (Test-Path $Exe) {+ try {+ $RunningProcesses = Get-Process -Name "moviebox-tui" -ErrorAction SilentlyContinue+ if ($RunningProcesses) {+ $RunningProcesses | Stop-Process -Force+ Start-Sleep -Seconds 1+ }+ Remove-Item -Path $Exe -Force -ErrorAction SilentlyContinue+ Write-Success "Removed $Exe"+ $Found = $true+ } catch {+ Write-Warn "Could not remove $Exe"}}- Write-Info "Updating MovieBox-TUI from v$CurrentVersion to $Version..."- $IsUpdate = $true-- $RunningProcesses = Get-Process -Name "moviebox-tui" -ErrorAction SilentlyContinue- if ($RunningProcesses) {- Write-Info "Stopping running instances of MovieBox-Tui..."- $RunningProcesses | Stop-Process -Force- Start-Sleep -Seconds 1- }- } catch {- Write-Info "Updating MovieBox-TUI to $Version..."- $IsUpdate = $true}-} else {- Write-Info "Installing MovieBox-TUI $Version..."++ if ($Found) {+ Write-Success "$AppName was successfully uninstalled."+ } else {+ Write-Warn "No installed binary of $BinName was found."+ }+ exit 0}+if ($Uninstall) {+ Do-Uninstall+}++Print-Header+$Architecture = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }if ($Architecture -eq "ARM64") {$ArchiveName = "MovieBox_Windows_arm64.zip"+ $PlatformName = "Windows (arm64)"} elseif ($Architecture -eq "AMD64") {$ArchiveName = "MovieBox_Windows_x64.zip"+ $PlatformName = "Windows (x64)"} else {Write-Err "Unsupported Windows architecture: $Architecture"}++Write-Step "[1/4] Checking environment & resolving version..."++$TargetVersion = $Version+if (-not $TargetVersion) {+ try {+ $Request = [System.Net.WebRequest]::Create("https://github.com/$Repo/releases/latest")+ $Request.AllowAutoRedirect = $false+ $Response = $Request.GetResponse()+ $Location = $Response.Headers["Location"]+ $TargetVersion = $Location.Split('/')[-1].Trim()+ $Response.Close()+ } catch {+ Write-Err "Failed to contact GitHub for latest release. Please check your internet connection."+ }+}++if (-not $TargetVersion) {+ Write-Err "Could not resolve latest release version from GitHub."+}++Write-Success "[1/4] Environment ready ($PlatformName • $TargetVersion)"++$EffectiveInstallDir = if ($InstallDir) { $InstallDir } else { $DefaultInstallDir }+$ExePath = Join-Path $EffectiveInstallDir $BinName++if (Test-Path $ExePath) {+ try {+ $CurrentVerOutput = (& $ExePath --version 2>&1 | Out-String)+ if ($CurrentVerOutput -match "moviebox-tui\s+([\d\.]+)") {+ $CurrentVer = "v" + $matches[1]+ if ($CurrentVer -eq $TargetVersion -and (-not $Force)) {+ Write-Success "MovieBox-TUI $TargetVersion is already installed at $ExePath. Use -Force to reinstall."+ exit 0+ }+ }+ } catch {+ # Proceed with installation if version check fails+ }+}++if ($DryRun) {+ Write-Success "[Dry Run] Target package: $ArchiveName"+ Write-Success "[Dry Run] Target install directory: $ExePath"+ Write-Success "[Dry Run] All preflight checks passed."+ exit 0+}+$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("moviebox-tui-" + [guid]::NewGuid())New-Item -ItemType Directory -Force -Path $TempDir | Out-Null+$ZipFile = Join-Path $TempDir $ArchiveName$ChecksumFile = Join-Path $TempDir "SHA256SUMS"-$BaseUrl = "https://github.com/mesamirh/MovieBox-Tui/releases/download/$Version"+$BaseUrl = "https://github.com/$Repo/releases/download/$TargetVersion"$Url = "$BaseUrl/$ArchiveName"-Write-Info "Downloading release archive..."try {+ Write-Step "[2/4] Downloading $ArchiveName..."Invoke-WebRequest -Uri $Url -OutFile $ZipFile -UseBasicParsingInvoke-WebRequest -Uri "$BaseUrl/SHA256SUMS" -OutFile $ChecksumFile -UseBasicParsing+ Write-Success "[2/4] Downloaded $ArchiveName"++ Write-Step "[3/4] Verifying SHA256 checksum..."+ $ChecksumLine = Get-Content $ChecksumFile | Where-Object { $_ -match "\s+$([regex]::Escape($ArchiveName))$" } | Select-Object -First 1+ if (-not $ChecksumLine) {+ throw "Release checksum is missing for $ArchiveName."+ }+ $ExpectedHash = ($ChecksumLine -split '\s+')[0].Trim().ToUpper()+ $ActualHash = (Get-FileHash -Path $ZipFile -Algorithm SHA256).Hash.Trim().ToUpper()+ if ($ActualHash -ne $ExpectedHash) {+ throw "Checksum verification failed."+ }+ Write-Success "[3/4] Cryptographic checksum verified"++ Write-Step "[4/4] Installing binary to $EffectiveInstallDir..."+ if (-not (Test-Path $EffectiveInstallDir)) {+ New-Item -ItemType Directory -Force -Path $EffectiveInstallDir | Out-Null+ }++ $RunningProcesses = Get-Process -Name "moviebox-tui" -ErrorAction SilentlyContinue+ if ($RunningProcesses) {+ $RunningProcesses | Stop-Process -Force+ Start-Sleep -Seconds 1+ }++ Expand-Archive -Path $ZipFile -DestinationPath $TempDir -Force+ $ExtractedExe = Join-Path $TempDir $BinName+ if (-not (Test-Path $ExtractedExe)) {+ throw "Binary not found in archive."+ }++ Move-Item -Path $ExtractedExe -Destination $ExePath -Force+ Write-Success "[4/4] Binary installed to $ExePath"} catch {Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue- Write-Err "Download failed. Please check your internet connection."+ Write-Err "Installation failed: $_"+} finally {+ Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue}-$ChecksumLine = Get-Content $ChecksumFile | Where-Object { $_ -match "\s+$([regex]::Escape($ArchiveName))$" } | Select-Object -First 1-if (-not $ChecksumLine) {- Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue- Write-Err "Release checksum is missing for $ArchiveName."+$PathModified = $false+if (-not $NoModifyPath) {+ $UserPath = [Environment]::GetEnvironmentVariable("PATH", "User")+ if ($UserPath -notmatch [regex]::Escape($EffectiveInstallDir)) {+ $NewPath = if ($UserPath) { "$UserPath;$EffectiveInstallDir" } else { $EffectiveInstallDir }+ [Environment]::SetEnvironmentVariable("PATH", $NewPath, "User")+ $PathModified = $true+ }}-$ExpectedHash = ($ChecksumLine -split '\s+')[0]-$ActualHash = (Get-FileHash -Path $ZipFile -Algorithm SHA256).Hash-if ($ActualHash -ne $ExpectedHash) {- Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue- Write-Err "Checksum verification failed."++$PlayerDetected = ""+if (Get-Command "mpv" -ErrorAction SilentlyContinue) {+ $PlayerDetected = "mpv"+} elseif (Get-Command "vlc" -ErrorAction SilentlyContinue) {+ $PlayerDetected = "VLC"}-if (-not (Test-Path $InstallDir)) {- New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null+Write-Host ""+Write-Host "┌────────────────────────────────────────────────────────────┐" -ForegroundColor Cyan+Write-Host "│ ✔ MovieBox-Tui $TargetVersion successfully installed! │" -ForegroundColor Cyan+Write-Host "│ │" -ForegroundColor Cyan+Write-Host "│ • Binary: $ExePath" -ForegroundColor Cyan++if ($PlayerDetected) {+ Write-Host "│ • Player: $PlayerDetected (ready)" -ForegroundColor Cyan+} else {+ Write-Host "│ • Player: None found (mpv / VLC required) │" -ForegroundColor Cyan}-Write-Info "Extracting files..."-try {- Expand-Archive -Path $ZipFile -DestinationPath $InstallDir -Force-} catch {- Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue- Write-Err "Failed to extract archive."+if ($PathModified) {+ Write-Host "│ • Shell: PATH updated in User Environment │" -ForegroundColor Cyan}-Remove-Item $TempDir -Recurse -Force+Write-Host "│ │" -ForegroundColor Cyan+Write-Host "│ To start streaming: │" -ForegroundColor Cyan+Write-Host "│ $ moviebox-tui │" -ForegroundColor Cyan+Write-Host "└────────────────────────────────────────────────────────────┘" -ForegroundColor Cyan+Write-Host ""-$UserPath = [Environment]::GetEnvironmentVariable("PATH", "User")-if ($UserPath -notmatch [regex]::Escape($InstallDir)) {- Write-Info "Adding $InstallDir to PATH..."- $NewPath = "$UserPath;$InstallDir"- [Environment]::SetEnvironmentVariable("PATH", $NewPath, "User")- Write-Warn "Please restart your PowerShell window for the PATH changes to take effect."+if (-not $PlayerDetected) {+ Write-Warn "No media player detected. Please install mpv, VLC, or IINA for video playback."}-if ($IsUpdate) {- Write-Success "Update complete! Run 'moviebox-tui' to start."-} else {- Write-Success "Installation complete! Run 'moviebox-tui' to start."+if ($PathModified) {+ Write-Host " ℹ Restart your terminal window for the updated PATH to take effect.`n" -ForegroundColor Cyan}diff --git a/install.sh b/install.shindex 9f406dd..d251527 100755--- a/install.sh+++ b/install.sh@@ -1,128 +1,510 @@#!/usr/bin/env bashset -euo pipefail-log_info() { echo -e "\033[0;34m$1\033[0m"; }-log_success() { echo -e "\033[0;32m$1\033[0m"; }-log_warn() { echo -e "\033[1;33mWARNING: $1\033[0m"; }-log_err() { echo -e "\033[0;31mERROR: $1\033[0m"; exit 1; }+APP_NAME="MovieBox-Tui"+BIN_NAME="moviebox-tui"+REPO="mesamirh/MovieBox-Tui"+DEFAULT_INSTALL_DIR="$HOME/.local/bin"-INSTALL_DIR="/usr/local/bin"+VERSION=""+CUSTOM_DIR=""+FORCE=0+DRY_RUN=0+NO_MODIFY_PATH=0+UNINSTALL=0-BIN_NAME="moviebox-tui"-APP_PATH="$INSTALL_DIR/$BIN_NAME"+for arg in "$@"; do+ case "$arg" in+ --version=*|-v=*)+ VERSION="${arg#*=}"+ ;;+ --version|-v)+ shift+ VERSION="${1:-}"+ ;;+ --dir=*)+ CUSTOM_DIR="${arg#*=}"+ ;;+ --dir)+ shift+ CUSTOM_DIR="${1:-}"+ ;;+ --force|-f)+ FORCE=1+ ;;+ --dry-run)+ DRY_RUN=1+ ;;+ --no-modify-path)+ NO_MODIFY_PATH=1+ ;;+ --uninstall)+ UNINSTALL=1+ ;;+ --help|-h)+ cat << 'EOF'+MovieBox-TUI Installer-sync_app_path() {- APP_PATH="$INSTALL_DIR/$BIN_NAME"-}+USAGE:+ curl -fsSL https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.sh | bash [OPTIONS]+ ./install.sh [OPTIONS]-command -v curl >/dev/null 2>&1 || log_err "curl is required but not installed. Please install it."-command -v tar >/dev/null 2>&1 || log_err "tar is required but not installed. Please install it."+OPTIONS:+ -v, --version <tag> Install a specific version (e.g. v0.1.11)+ --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+ ;;+ esac+done-log_info "Fetching latest version information..."-if ! LATEST_RELEASE=$(curl -fsSI "https://github.com/mesamirh/MovieBox-Tui/releases/latest"); then- log_err "Failed to fetch latest version from GitHub."+IS_TTY=0+if [ -t 1 ] && [ -t 0 ]; then+ IS_TTY=1fi-VERSION=$(echo "$LATEST_RELEASE" | grep -i '^location:' | awk -F '/' '{print $NF}' | tr -d '\r') || true-[ -z "$VERSION" ] && log_err "Failed to fetch latest version from GitHub API."-if command -v "$BIN_NAME" > /dev/null 2>&1; then- CURRENT_VERSION=$($BIN_NAME --version 2>/dev/null | awk '{print $2}') || true- CURRENT_VERSION=${CURRENT_VERSION:-unknown}+IS_COLOR=0+if [ -z "${NO_COLOR:-}" ] && [ "${TERM:-}" != "dumb" ] && [ -t 1 ]; then+ IS_COLOR=1+fi- if [ "v$CURRENT_VERSION" = "$VERSION" ]; then- log_success "You already have the latest version ($VERSION) installed."- exit 0- fi- log_info "Updating MovieBox-TUI from v$CURRENT_VERSION to $VERSION..."- IS_UPDATE=1+if [ "$IS_COLOR" -eq 1 ]; then+ C_RESET="\033[0m"+ C_BOLD="\033[1m"+ C_DIM="\033[2m"+ C_CYAN="\033[36m"+ C_BOLD_CYAN="\033[1;36m"+ C_GREEN="\033[32m"+ C_BOLD_GREEN="\033[1;32m"+ C_YELLOW="\033[33m"+ C_BOLD_YELLOW="\033[1;33m"+ C_RED="\033[31m"+ C_BOLD_RED="\033[1;31m"+ C_MAGENTA="\033[35m"+ C_BLUE="\033[34m"+ CURSOR_HIDE="\033[?25l"+ CURSOR_SHOW="\033[?25h"else- log_info "Installing MovieBox-TUI $VERSION..."- IS_UPDATE=0+ C_RESET=""+ C_BOLD=""+ C_DIM=""+ C_CYAN=""+ C_BOLD_CYAN=""+ C_GREEN=""+ C_BOLD_GREEN=""+ C_YELLOW=""+ C_BOLD_YELLOW=""+ C_RED=""+ C_BOLD_RED=""+ C_MAGENTA=""+ C_BLUE=""+ CURSOR_HIDE=""+ CURSOR_SHOW=""fi+cleanup() {+ printf "%b" "$CURSOR_SHOW" 2>/dev/null || true+ if [ -n "${TMP_DIR:-}" ] && [ -d "$TMP_DIR" ]; then+ rm -rf "$TMP_DIR"+ fi+}+trap cleanup EXIT INT TERM++log_step() {+ printf " %b%s%b %s\n" "$C_BOLD_CYAN" "→" "$C_RESET" "$1"+}++log_success() {+ printf " %b%s%b %s\n" "$C_BOLD_GREEN" "✔" "$C_RESET" "$1"+}++log_warn() {+ printf " %b%s%b %s\n" "$C_BOLD_YELLOW" "⚠" "$C_RESET" "$1"+}++log_error() {+ printf " %b%s%b %s\n" "$C_BOLD_RED" "✖" "$C_RESET" "$1" >&2+}++print_header() {+ if [ "$IS_COLOR" -eq 1 ] && [ "$IS_TTY" -eq 1 ]; then+ printf "%b\n" "$CURSOR_HIDE"+ printf "%b" "$C_BOLD_CYAN"+ local lines=(+ "███╗ ███╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗"+ "████╗ ████║ ██╔═══██╗ ██║ ██║ ██║ ██╔════╝ ██╔══██╗ ██╔═══██╗ ╚██╗██╔╝"+ "██╔████╔██║ ██║ ██║ ██║ ██║ ██║ █████╗ ██████╔╝ ██║ ██║ ╚███╔╝ "+ "██║╚██╔╝██║ ██║ ██║ ╚██╗ ██╔╝ ██║ ██╔══╝ ██╔══██╗ ██║ ██║ ██╔██╗ "+ "██║ ╚═╝ ██║ ╚██████╔╝ ╚████╔╝ ██║ ███████╗ ██████╔╝ ╚██████╔╝ ██╔╝ ██╗"+ "╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝"+ )+ for line in "${lines[@]}"; do+ printf "%s\n" "$line"+ sleep 0.02+ done+ printf "%b%b%s%b\n\n" "$C_DIM" " MovieBox-Tui Installer" "$C_RESET" "$CURSOR_SHOW"+ else+ cat << 'EOF'+███╗ ███╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗+████╗ ████║ ██╔═══██╗ ██║ ██║ ██║ ██╔════╝ ██╔══██╗ ██╔═══██╗ ╚██╗██╔╝+██╔████╔██║ ██║ ██║ ██║ ██║ ██║ █████╗ ██████╔╝ ██║ ██║ ╚███╔╝+██║╚██╔╝██║ ██║ ██║ ╚██╗ ██╔╝ ██║ ██╔══╝ ██╔══██╗ ██║ ██║ ██╔██╗+██║ ╚═╝ ██║ ╚██████╔╝ ╚████╔╝ ██║ ███████╗ ██████╔╝ ╚██████╔╝ ██╔╝ ██╗+╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝+ MovieBox-Tui Installer++EOF+ 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 %s..." "$C_CYAN" "$frame" "$C_RESET" "$message"+ 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"+ "${PREFIX:-}/bin/$BIN_NAME"+ )++ 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+fiif [ "$OS" = "Darwin" ]; thenFILE="MovieBox_macOS_Universal.tar.gz"-elif [ -n "${PREFIX:-}" ] && [[ "$PREFIX" == *com.termux* ]]; then+ PLATFORM_NAME="macOS (Universal)"+elif [ "$IS_TERMUX" -eq 1 ]; thenif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; thenFILE="MovieBox_Termux_arm64.tar.gz"- INSTALL_DIR="$PREFIX/bin"- sync_app_path+ PLATFORM_NAME="Android Termux (arm64)"else- log_err "Unsupported Termux architecture ($ARCH). Only arm64/aarch64 is natively hosted. Please use cargo install."+ log_error "Unsupported Termux architecture ($ARCH). Only arm64/aarch64 is hosted. Use 'cargo install moviebox-tui'."+ exit 1fielif [ "$OS" = "Linux" ]; thenif [ "$ARCH" = "x86_64" ]; thenFILE="MovieBox_Linux_x64.tar.gz"+ PLATFORM_NAME="Linux (x86_64)"elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; thenFILE="MovieBox_Linux_arm64.tar.gz"+ PLATFORM_NAME="Linux (arm64)"else- log_err "Unsupported Linux architecture ($ARCH). Only x86_64 and arm64 are supported."+ log_error "Unsupported Linux architecture ($ARCH). Only x86_64 and arm64 are supported."+ exit 1fielse- log_err "Unsupported OS ($OS)."+ log_error "Unsupported Operating System ($OS)."+ exit 1fi-URL="https://github.com/mesamirh/MovieBox-Tui/releases/download/$VERSION/$FILE"-CHECKSUM_URL="https://github.com/mesamirh/MovieBox-Tui/releases/download/$VERSION/SHA256SUMS"-TMP_DIR=$(mktemp -d)-trap 'rm -rf "$TMP_DIR"' EXIT+resolve_version() {+ if [ -n "$VERSION" ]; then+ TARGET_VERSION="$VERSION"+ return 0+ fi-log_info "Downloading $FILE..."-if ! curl -fSL "$URL" -o "$TMP_DIR/$FILE"; then- log_err "Download failed. Please check your internet connection."-fi+ local release_header+ release_header=$(curl -fsSI "https://github.com/$REPO/releases/latest") || {+ log_error "Failed to contact GitHub for latest release."+ return 1+ }+ TARGET_VERSION=$(printf "%s" "$release_header" | grep -i '^location:' | awk -F '/' '{print $NF}' | tr -d '\r\n')+ if [ -z "$TARGET_VERSION" ]; then+ log_error "Could not resolve latest release version from GitHub."+ return 1+ fi+}-if ! curl -fsSL "$CHECKSUM_URL" -o "$TMP_DIR/SHA256SUMS"; then- log_err "Checksum download failed. Refusing unverified installation."-fi-EXPECTED_SHA=$(awk -v file="$FILE" '$2 == file {print $1}' "$TMP_DIR/SHA256SUMS")-[ -z "$EXPECTED_SHA" ] && log_err "Release checksum is missing for $FILE."-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}')+TARGET_VERSION=""+run_spinner "[1/4] Checking environment & resolving version" resolve_version+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- log_err "sha256sum or shasum is required to verify the release."+ INSTALL_DIR="$DEFAULT_INSTALL_DIR"fi-[ "$ACTUAL_SHA" != "$EXPECTED_SHA" ] && log_err "Checksum verification failed."-log_info "Extracting files..."-tar -xzf "$TMP_DIR/$FILE" -C "$TMP_DIR"+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 [ ! -f "$TMP_DIR/$BIN_NAME" ]; then- log_err "Binary not found in archive. This is an unexpected packaging error."+ 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 %s\n" "$C_BOLD_YELLOW" "ℹ" "$C_RESET" "MovieBox-TUI $TARGET_VERSION is already installed at $EXISTING_BIN."+ printf " Choose an action: [1] Reinstall [2] Uninstall [3] Exit: "+ read -r user_choice || user_choice="3"+ 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 0fi-log_info "Moving binary to $INSTALL_DIR..."-if [ -d "$INSTALL_DIR" ] && [ -w "$INSTALL_DIR" ]; then- install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH"-elif command -v sudo >/dev/null 2>&1; then- log_info "Requires sudo privileges to write to $INSTALL_DIR..."- if sudo mkdir -p "$INSTALL_DIR" && sudo install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH"; then- :+TMP_DIR=$(mktemp -d)++URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/$FILE"+CHECKSUM_URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/SHA256SUMS"++download_files() {+ curl -fSL "$URL" -o "$TMP_DIR/$FILE" && \+ curl -fsSL "$CHECKSUM_URL" -o "$TMP_DIR/SHA256SUMS"+}++run_spinner "[2/4] Downloading $FILE" download_files+log_success "[2/4] Downloaded $FILE"++verify_checksum() {+ local expected_sha+ expected_sha=$(awk -v file="$FILE" '$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+log_success "[3/4] Cryptographic checksum verified"++install_binary() {+ tar -xzf "$TMP_DIR/$FILE" -C "$TMP_DIR"+ if [ ! -f "$TMP_DIR/$BIN_NAME" ]; then+ return 1+ fi++ mkdir -p "$INSTALL_DIR" 2>/dev/null || true+ if [ -w "$INSTALL_DIR" ] || [ -w "$(dirname "$INSTALL_DIR")" ]; then+ mkdir -p "$INSTALL_DIR"+ install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH" 2>/dev/null || {+ cp "$TMP_DIR/$BIN_NAME" "$APP_PATH"+ chmod 755 "$APP_PATH"+ }+ elif command -v sudo >/dev/null 2>&1; then+ sudo mkdir -p "$INSTALL_DIR"+ sudo install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH" 2>/dev/null || {+ sudo cp "$TMP_DIR/$BIN_NAME" "$APP_PATH"+ sudo chmod 755 "$APP_PATH"+ }else- log_warn "Sudo access failed or was cancelled. Falling back to local installation..."INSTALL_DIR="$HOME/.local/bin"- sync_app_path+ APP_PATH="$INSTALL_DIR/$BIN_NAME"mkdir -p "$INSTALL_DIR"- install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH"+ cp "$TMP_DIR/$BIN_NAME" "$APP_PATH"+ chmod 755 "$APP_PATH"+ fi+}++run_spinner "[4/4] Installing binary to $INSTALL_DIR" install_binary+log_success "[4/4] Binary installed to $APP_PATH"++SHELL_MODIFIED=""+if [ "$NO_MODIFY_PATH" -eq 0 ]; then+ if ! echo "$PATH" | tr ':' '\n' | grep -q "^$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 -q "$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+ fifi-else- INSTALL_DIR="$HOME/.local/bin"- sync_app_path- mkdir -p "$INSTALL_DIR"- install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH"fi-if ! echo "$PATH" | tr ':' '\n' | grep -q "^$INSTALL_DIR$"; then- log_warn "$INSTALL_DIR is not in your PATH. You may need to add it to run $BIN_NAME easily."+PLAYER_DETECTED=""+if command -v mpv >/dev/null 2>&1; then+ PLAYER_DETECTED="mpv"+elif command -v iina >/dev/null 2>&1 || command -v iina-cli >/dev/null 2>&1; then+ PLAYER_DETECTED="IINA"+elif command -v vlc >/dev/null 2>&1; then+ PLAYER_DETECTED="VLC"fi-if [ "$IS_UPDATE" -eq 1 ]; then- log_success "Update complete! Run '$BIN_NAME' to start."+printf "\n"+printf "%b┌────────────────────────────────────────────────────────────┐%b\n" "$C_BOLD_CYAN" "$C_RESET"+printf "%b│%b %b✔ MovieBox-Tui %s successfully installed!%b%*s%b│%b\n" \+ "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD_GREEN" "$TARGET_VERSION" "$C_RESET" \+ $(( 28 - ${#TARGET_VERSION} )) "" "$C_BOLD_CYAN" "$C_RESET"+printf "%b│%b %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"+printf "%b│%b • Binary: %b%-45s%b %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD" "$APP_PATH" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"++if [ -n "$PLAYER_DETECTED" ]; then+ printf "%b│%b • Player: %b%-45s%b %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_GREEN" "$PLAYER_DETECTED (ready)" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"else- log_success "Installation complete! Run '$BIN_NAME' to start."+ printf "%b│%b • Player: %b%-45s%b %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_YELLOW" "None found (mpv / VLC / IINA required)" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"+fi++if [ -n "$SHELL_MODIFIED" ]; then+ printf "%b│%b • Shell: %bPATH added to %-31s%b %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_CYAN" "$SHELL_MODIFIED" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"+fi++printf "%b│%b %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"+printf "%b│%b To start streaming: %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"+printf "%b│%b %b$ moviebox-tui%b %b│%b\n" "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD_CYAN" "$C_RESET"+printf "%b└────────────────────────────────────────────────────────────┘%b\n\n" "$C_BOLD_CYAN" "$C_RESET"++if [ -z "$PLAYER_DETECTED" ]; then+ log_warn "No media player detected. Please install mpv, VLC, or IINA for video playback."+fi++if [ -n "$SHELL_MODIFIED" ]; then+ printf " %bℹ%b Run %b'source %s'%b or restart your terminal to reload PATH.\n\n" "$C_BOLD_CYAN" "$C_RESET" "$C_BOLD" "$SHELL_MODIFIED" "$C_RESET"fi