Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

feat: add version checking to installation scripts and replace API calls with redirect-based resolution

Samir Hossains696f04c52446
diff --git a/install.ps1 b/install.ps1
index 058c2d5..4e3497b 100644
--- a/install.ps1
+++ b/install.ps1
@@ -12,24 +12,44 @@ $ZipFile = "$env:TEMP\MovieBox_Windows_x64.zip"
Write-Info "Fetching latest version information..."
try {
- $Release = Invoke-RestMethod -Uri "https://api.github.com/repos/mesamirh/MovieBox-Tui/releases/latest" -UseBasicParsing
- $Version = $Release.tag_name
- if (-not $Version) { throw "Version not found in API response." }
+ $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."
}
$IsUpdate = $false
if (Test-Path $ExePath) {
- Write-Info "MovieBox-TUI is already installed. Forcing update to $Version..."
- $IsUpdate = $true
-
- # Ensure it's not running
- $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
+ try {
+ $Strings = (Select-String -Path $ExePath -Pattern "--version" -Quiet -ErrorAction SilentlyContinue)
+ if ($Strings) {
+ $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
+ }
+ }
+ }
+ if (-not $CurrentVersion) { $CurrentVersion = "unknown" }
+ 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..."
diff --git a/install.sh b/install.sh
old mode 100644
new mode 100755
index 9ba882e..add2e25
--- a/install.sh
+++ b/install.sh
@@ -1,7 +1,6 @@
#!/bin/bash
set -e
-# Logging Helpers
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"; }
@@ -11,25 +10,36 @@ INSTALL_DIR="/usr/local/bin"
BIN_NAME="moviebox-tui"
APP_PATH="$INSTALL_DIR/$BIN_NAME"
-# Dependency Checks
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."
-# Version Detection
log_info "Fetching latest version information..."
-LATEST_RELEASE=$(curl -s "https://api.github.com/repos/mesamirh/MovieBox-Tui/releases/latest")
-VERSION=$(echo "$LATEST_RELEASE" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
+LATEST_RELEASE=$(curl -sI "https://github.com/mesamirh/MovieBox-Tui/releases/latest")
+VERSION=$(echo "$LATEST_RELEASE" | grep -i '^location:' | awk -F '/' '{print $NF}' | tr -d '\r')
[ -z "$VERSION" ] && log_err "Failed to fetch latest version from GitHub API."
if command -v "$BIN_NAME" > /dev/null 2>&1; then
- log_info "MovieBox-TUI is already installed. Forcing update to $VERSION..."
+ if strings "$APP_PATH" 2>/dev/null | grep -q "\-\-version"; then
+ CURRENT_VERSION=$($BIN_NAME --version 2>/dev/null | awk '{print $2}')
+ else
+ CURRENT_VERSION="unknown"
+ fi
+
+ if [ -z "$CURRENT_VERSION" ]; then
+ CURRENT_VERSION="unknown"
+ 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
else
log_info "Installing MovieBox-TUI $VERSION..."
IS_UPDATE=0
fi
-# OS/Architecture Detection
OS="$(uname -s)"
ARCH="$(uname -m)"
@@ -73,7 +83,6 @@ else
sudo chmod +x "$APP_PATH"
fi
-# PATH check
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."
fi