#!/usr/bin/env bash set -e usage() { cat </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---.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 "========================================"