install_desktop.sh
Rama main · réplica de lectura del repositorio original.
#!/usr/bin/env bash
set -e
usage() {
cat <<EOF
Usage: $0 [OPTIONS]
Options:
-p, --pre-release Download latest pre-release instead of stable
-h, --help Show this help message
EOF
exit 0
}
PRE_RELEASE=false
while [[ $# -gt 0 ]]; do
case "$1" in
-p|--pre-release) PRE_RELEASE=true ;;
-h|--help) usage ;;
*) echo "Unknown option: $1"; usage ;;
esac
shift
done
echo "========================================"
echo "RSPlayer Desktop Installer"
echo "========================================"
if [ "$(id -u)" -eq 0 ]; then
SUDO=""
else
SUDO="sudo"
fi
device_arch=$(uname -m)
echo "[INFO] Device architecture: $device_arch"
if [ "$device_arch" = "x86_64" ]; then
deb_arch_suffix="amd64"
rpm_arch_suffix="x86_64"
arch_arch_suffix="x86_64"
elif [ "$device_arch" = "aarch64" ]; then
deb_arch_suffix="arm64"
rpm_arch_suffix="aarch64"
arch_arch_suffix="aarch64"
elif [ "$device_arch" = "armv7l" ]; then
deb_arch_suffix="armhfv7"
rpm_arch_suffix="armv7hl"
arch_arch_suffix="armv7h"
elif [ "$device_arch" = "armv6l" ]; then
deb_arch_suffix="armhfv6"
rpm_arch_suffix="armv6hl"
arch_arch_suffix="armv6h"
elif [ "$device_arch" = "riscv64" ]; then
deb_arch_suffix="riscv64"
rpm_arch_suffix="riscv64"
arch_arch_suffix="riscv64"
else
deb_arch_suffix=$device_arch
rpm_arch_suffix=$device_arch
arch_arch_suffix=$device_arch
fi
echo "[INFO] Architecture suffixes: deb=$deb_arch_suffix rpm=$rpm_arch_suffix arch=$arch_arch_suffix"
echo "[INFO] Detecting distribution..."
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "[INFO] OS: $PRETTY_NAME (ID=$ID)"
case $ID in
debian|ubuntu|raspbian)
pkg_type="deb"
pkg_suffix="$deb_arch_suffix"
pkg_ext="deb"
;;
fedora|rhel|centos|opensuse*)
pkg_type="rpm"
pkg_suffix="$rpm_arch_suffix"
pkg_ext="rpm"
;;
arch|archarm|manjaro)
pkg_type="arch"
pkg_suffix="$arch_arch_suffix"
pkg_ext="pkg.tar.zst"
;;
*)
echo "[WARN] Unknown distribution '$ID', defaulting to deb"
pkg_type="deb"
pkg_suffix="$deb_arch_suffix"
pkg_ext="deb"
;;
esac
else
echo "[WARN] /etc/os-release not found, assuming Debian-based"
pkg_type="deb"
pkg_suffix="$deb_arch_suffix"
pkg_ext="deb"
fi
echo "[INFO] Selected package type: $pkg_type (suffix=$pkg_suffix, ext=$pkg_ext)"
REPO_URL="https://ljufa.github.io/rsplayer-pkg"
setup_apt_repo() {
echo "[INFO] Adding RSPlayer apt repository ($REPO_URL/deb)"
curl -fsSL "$REPO_URL/rsplayer.gpg" -o /tmp/rsplayer-keyring.gpg &&
$SUDO install -D -m 644 /tmp/rsplayer-keyring.gpg /usr/share/keyrings/rsplayer.gpg &&
rm -f /tmp/rsplayer-keyring.gpg &&
echo "deb [signed-by=/usr/share/keyrings/rsplayer.gpg] $REPO_URL/deb stable main" | $SUDO tee /etc/apt/sources.list.d/rsplayer.list >/dev/null &&
$SUDO apt-get update &&
$SUDO apt-get install -y rsplayer-desktop
}
setup_dnf_repo() {
echo "[INFO] Adding RSPlayer dnf repository ($REPO_URL/rpm)"
curl -fsSL "$REPO_URL/rpm/rsplayer.repo" -o /tmp/rsplayer.repo &&
$SUDO install -m 644 /tmp/rsplayer.repo /etc/yum.repos.d/rsplayer.repo &&
rm -f /tmp/rsplayer.repo &&
$SUDO dnf install -y rsplayer-desktop
}
# Prefer the package repository (updates via apt/dnf upgrade). Desktop
# packages exist for x86_64 and aarch64; other arches use the direct download below.
# The repo entry is kept on failure — it may already serve the server package.
repo_install_done=false
if [ "$PRE_RELEASE" = false ] && { [ "$device_arch" = "x86_64" ] || [ "$device_arch" = "aarch64" ]; }; then
case $pkg_type in
deb)
if setup_apt_repo; then
repo_install_done=true
else
echo "[WARN] Repo-based install failed, falling back to direct package download"
fi
;;
rpm)
if setup_dnf_repo; then
repo_install_done=true
else
echo "[WARN] Repo-based install failed, falling back to direct package download"
fi
;;
esac
fi
try_download() {
local type=$1
local suffix=$2
local ext=$3
local file="rsplayer-desktop_${suffix}.${ext}"
# Arch: rsplayer-desktop-bin-<ver>-<rel>-<carch>.pkg.tar.zst
local pattern="/rsplayer-desktop[^/]*[-_.]${suffix}\.${ext}$"
if [ "$type" = "arch" ]; then
pattern="/rsplayer-desktop-bin-[^/]*-${suffix}\.pkg\.tar\.zst$"
fi
if [ "$PRE_RELEASE" = true ]; then
echo "[INFO] Querying GitHub API for latest pre-release..."
URL=$(curl -s "https://api.github.com/repos/ljufa/rsplayer/releases?per_page=1" | grep browser_download_url | cut -d '"' -f 4 | grep -E "$pattern" | head -n 1)
else
echo "[INFO] Querying GitHub API for latest stable release..."
URL=$(curl -s "https://api.github.com/repos/ljufa/rsplayer/releases/latest" | grep browser_download_url | cut -d '"' -f 4 | grep -E "$pattern" | head -n 1)
fi
if [ -z "$URL" ]; then
echo "[WARN] No $type desktop package found for suffix=$suffix ext=$ext"
return 1
fi
echo "[INFO] Downloading: $URL"
if curl -L -o "$file" "$URL"; then
echo "[INFO] Download OK: $file ($(du -h "$file" | cut -f1))"
pkg_type="$type"
pkg_suffix="$suffix"
pkg_ext="$ext"
pkg_file_name="$file"
return 0
else
echo "[ERROR] Download failed"
rm -f "$file"
return 1
fi
}
# Sets overwrite_args to --overwrite for each file of package $1 that is already
# on disk without a pacman owner (left there by an earlier tarball install).
overwrite_unowned() {
overwrite_args=()
local path
while read -r path; do
if [ -f "$path" ] && ! pacman -Qo "$path" >/dev/null 2>&1; then
overwrite_args+=(--overwrite "$path")
fi
done < <(pacman -Qlpq "$1")
}
# Direct-download install (pre-releases, other arches, Arch, repo fallback)
if [ "$repo_install_done" = false ]; then
echo "[INFO] Attempting primary package type: $pkg_type"
if ! try_download "$pkg_type" "$pkg_suffix" "$pkg_ext"; then
if [ "$pkg_type" = "arch" ]; then
echo "[ERROR] No Arch desktop package found for $device_arch in this release."
exit 1
fi
echo "[WARN] Primary package type $pkg_type not available, falling back to DEB"
if ! try_download "deb" "$deb_arch_suffix" "deb"; then
echo "[ERROR] No suitable desktop package found for architecture $device_arch"
exit 1
fi
fi
echo "[INFO] Installing $pkg_type desktop package: $pkg_file_name"
case $pkg_type in
deb)
echo "[INFO] Installing deb with apt-get (resolves dependencies automatically)"
$SUDO apt-get update
$SUDO apt-get install "./${pkg_file_name}" || {
echo "[INFO] Retrying with dpkg + apt-get -f install to resolve dependencies"
$SUDO dpkg -i --force-overwrite "./${pkg_file_name}" || true
$SUDO apt-get install -f
}
;;
rpm)
echo "[INFO] Installing rpm with dnf (resolves dependencies automatically)"
$SUDO dnf install "./${pkg_file_name}"
;;
arch)
# Take over files left on disk by an earlier installer version, which
# extracted a tarball to / instead of installing a package.
overwrite_unowned "./${pkg_file_name}"
echo "[INFO] Installing with pacman (resolves dependencies automatically)"
$SUDO pacman -U "${overwrite_args[@]}" "./${pkg_file_name}"
;;
esac
rm "${pkg_file_name}"
fi # repo_install_done
echo "========================================"
echo "[INFO] Desktop installation complete!"
echo "[INFO] Package type: $pkg_type"
echo "[INFO] Architecture: $device_arch ($pkg_suffix)"
echo "========================================"
echo "[INFO] You can launch RSPlayer from your application menu"
echo " or by running 'rsplayer-desktop' in a terminal"
echo "========================================"