#!/usr/bin/env bash set -e usage() { cat </dev/null && $SUDO apt-get update && $SUDO apt-get install -y rsplayer } 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 } # Prefer the package repository: after the one-time setup, updates arrive via # regular apt/dnf upgrade. Pre-release installs and Arch/unknown distros use # the direct-download path below (also the fallback if the repo fails). repo_install_done=false if [ "$PRE_RELEASE" = false ]; then case $pkg_type in deb) if setup_apt_repo; then repo_install_done=true else echo "[WARN] Repo-based install failed, removing repo entry and falling back to direct package download" $SUDO rm -f /etc/apt/sources.list.d/rsplayer.list fi ;; rpm) if setup_dnf_repo; then repo_install_done=true else echo "[WARN] Repo-based install failed, removing repo entry and falling back to direct package download" $SUDO rm -f /etc/yum.repos.d/rsplayer.repo fi ;; esac fi # Function to attempt download try_download() { local type=$1 local suffix=$2 local ext=$3 local file="rsplayer_${suffix}.${ext}" # Server asset names: rsplayer__.deb/.rpm, Arch: rsplayer-bin---.pkg.tar.zst local pattern="/rsplayer_[^/]*_${suffix}\.${ext}$" if [ "$type" = "arch" ]; then pattern="/rsplayer-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 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))" chmod 644 "$file" 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, Arch, unknown distros, repo fallback) if [ "$repo_install_done" = false ]; then # Try primary package type 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 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 package found for architecture $device_arch" exit 1 fi fi echo "[INFO] Installing $pkg_type 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) # An earlier installer version extracted a tarball to / instead. Remove # its unit and polkit rule (the package ships them under /usr), and let # pacman take over the other files it left behind. for f in /etc/systemd/system/rsplayer.service /etc/polkit-1/rules.d/99-rsplayer.rules; do # sudo: /etc/polkit-1/rules.d is not readable by regular users if $SUDO test -f "$f" && ! pacman -Qo "$f" >/dev/null 2>&1; then echo "[INFO] Removing $f from a previous tarball install" $SUDO rm -f "$f" fi done overwrite_unowned "./${pkg_file_name}" echo "[INFO] Installing with pacman (resolves dependencies, sets up the service)" $SUDO pacman -U "${overwrite_args[@]}" "./${pkg_file_name}" ;; esac rm "${pkg_file_name}" fi # repo_install_done # Ensure /opt/rsplayer is owned by rsplayer regardless of package type echo "[INFO] Ensuring /opt/rsplayer ownership..." if getent passwd rsplayer >/dev/null 2>&1; then $SUDO chown -R rsplayer /opt/rsplayer echo "[INFO] /opt/rsplayer owned by rsplayer:rsplayer" else echo "[WARN] rsplayer user not found, skipping chown" fi # Work out the web UI address to show the user (port from the packaged env file) ui_port=$(grep -s '^PORT=' /opt/rsplayer/env | cut -d= -f2 | tr -d '"' || true) ui_port=${ui_port:-80} ui_host=$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{for (i = 1; i < NF; i++) if ($i == "src") { print $(i + 1); exit }}' || true) [ -n "$ui_host" ] || ui_host=$(hostname -I 2>/dev/null | awk '{print $1}' || true) ui_host=${ui_host:-localhost} if [ "$ui_port" = "80" ]; then ui_url="http://${ui_host}" else ui_url="http://${ui_host}:${ui_port}" fi echo "========================================" echo "[INFO] Installation complete!" echo "[INFO] Package type: $pkg_type" echo "[INFO] Architecture: $device_arch ($pkg_suffix)" echo "========================================" if systemctl is-active --quiet rsplayer 2>/dev/null; then echo " RSPlayer is running. Open it in your browser:" echo "" echo " $ui_url" else echo "[WARN] The rsplayer service is not running yet. Start it with:" echo " sudo systemctl start rsplayer" echo " then open it in your browser:" echo "" echo " $ui_url" fi echo "" echo " Useful commands:" echo " systemctl status rsplayer" echo " journalctl -u rsplayer -f -n 50" echo "========================================"