diff --git a/scripts/install/jellyfin.sh b/scripts/install/jellyfin.sh index 895ae882f..a59a45b94 100755 --- a/scripts/install/jellyfin.sh +++ b/scripts/install/jellyfin.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# authors: liara userdocs flying-sausages +# authors: liara userdocs flying-sausages katiethedev # # Licensed under GNU General Public License v3.0 GPL-3 (in short) # @@ -11,16 +11,10 @@ # Source the global functions we require for this script. . /etc/swizzin/sources/functions/utils . /etc/swizzin/sources/functions/ssl -# -# awaiting pull to remove -function dist_info() { - DIST_CODENAME="$(source /etc/os-release && echo "$VERSION_CODENAME")" - DIST_ID="$(source /etc/os-release && echo "$ID")" -} + # # Get our some useful information from functions in the sourced utils script username="$(_get_master_username)" -dist_info # get our distribution ID, set to DIST_ID, and VERSION_CODENAME, set to DIST_CODENAME, from /etc/os-release if [[ $(systemctl is-active emby) == "active" ]]; then active=emby @@ -40,6 +34,17 @@ if [[ -n $active ]]; then fi fi +# +## Get the path to gpg or install it +GNUPG=$(which gpg) +if [[ -z ${GNUPG} ]]; then + echo "Failed to find the GNUPG binary, but we'll install 'gnupg' automatically." + # shellcheck disable=SC2206 + # We are OK with word-splitting here since we control the contents + INSTALL_PKGS=(${INSTALL_PKGS[@]} gnupg) + echo +fi + # ######## ######## Variables End @@ -114,14 +119,39 @@ cat > /etc/jellyfin/network.xml <<- CONFIG CONFIG # -# Add the jellyfin official repository and key to our installation so we can use apt-get to install it jellyfin and jellyfin-ffmepg. -curl -s "https://repo.jellyfin.org/$DIST_ID/jellyfin_team.gpg.key" | gpg --dearmor > /usr/share/keyrings/jellyfin-archive-keyring.gpg 2>> "${log}" -echo "deb [signed-by=/usr/share/keyrings/jellyfin-archive-keyring.gpg arch=$(dpkg --print-architecture)] https://repo.jellyfin.org/$DIST_ID $DIST_CODENAME main" > /etc/apt/sources.list.d/jellyfin.list +# Check if old, outdated repository for jellyfin is installed +# If old repository is found, delete it. +if [[ -f /etc/apt/sources.list.d/jellyfin.list ]]; then + echo_progress_start "Found old-style '/etc/apt/sources.list.d/jellyfin.list' configuration; removing it." + rm -f /etc/apt/sources.list.d/jellyfin.list + echo_progress_done "Removed old configuration." + echo_success "Old repository has been removed." +fi + # -# install jellyfin and jellyfin-ffmepg using apt functions. +# Add Jellyfin signing key +curl -fsSL https://repo.jellyfin.org/jellyfin_team.gpg.key | gpg --dearmor --yes --output /etc/apt/keyrings/jellyfin.gpg +echo_success "Jellyfin Signing Key Added" + +# +# Install the Deb822 format jellyfin.sources entry +add_jellyfin_repo + +# +# Update apt repositories to fetch Jellyfin repository apt_update #forces apt refresh + +# +# Install Jellyfin and dependencies using apt +# Dependencies are automatically grabbed by apt apt_install jellyfin +# +# Make sure Jellyfin finishes starting up before continuing. +echo_progress_start "Waiting for Jellyfin to start." +sleep 15 +echo_progress_done "Jellyfin should be started." + # # Add the jellyfin user to the master user's group. usermod -a -G "${username}" jellyfin diff --git a/scripts/update/jellyfin.sh b/scripts/update/jellyfin.sh index 898489b5b..9fd43387f 100755 --- a/scripts/update/jellyfin.sh +++ b/scripts/update/jellyfin.sh @@ -1,24 +1,18 @@ #!/usr/bin/env bash # if [[ -f /install/.jellyfin.lock ]]; then - # awaiting pull to remove - function dist_info() { - DIST_CODENAME="$(source /etc/os-release && echo "$VERSION_CODENAME")" - DIST_ID="$(source /etc/os-release && echo "$ID")" - } # source the functions we need for this script. #shellcheck source=sources/functions/utils . /etc/swizzin/sources/functions/utils # Get our main user credentials using a util function. username="$(_get_master_username)" - dist_info # get our distribution ID, set to DIST_ID, and VERSION_CODENAME, set to DIST_CODENAME, from /etc/os-release # # remove the old service and remove legacy files. if [[ -f /etc/systemd/system/jellyfin.service ]]; then echo_progress_start "Removing old Jellyfin service" + systemctl stop jellyfin.service systemctl -q disable --now jellyfin.service rm_if_exists /etc/systemd/system/jellyfin.service - kill -9 $(ps xU "${username}" | grep "/opt/jellyfin/jellyfin -d /home/${username}/.config/Jellyfin$" | awk '{print $1}') > /dev/null 2>&1 rm_if_exists /opt/jellyfin rm_if_exists /opt/ffmpeg echo_progress_done "Old JF service removed" @@ -68,17 +62,42 @@ if [[ -f /install/.jellyfin.lock ]]; then fi # if ! check_installed jellyfin; then - echo_progress_start "Moving Jellyfin to apt-managed installation" + echo_progress_start "Updating Jellyfin installation using apt." + # - # Add the jellyfin official repository and key to our installation so we can use apt-get to install it jellyfin and jellyfin-ffmepg. - curl -s https://repo.jellyfin.org/$DIST_ID/jellyfin_team.gpg.key | gpg --dearmor > /usr/share/keyrings/jellyfin-archive-keyring.gpg 2>> "${log}" - echo "deb [signed-by=/usr/share/keyrings/jellyfin-archive-keyring.gpg arch=$(dpkg --print-architecture)] https://repo.jellyfin.org/$DIST_ID $DIST_CODENAME main" > /etc/apt/sources.list.d/jellyfin.list + # Check if old, outdated repository for jellyfin is installed + # If old repository is found, delete it. + if [[ -f /etc/apt/sources.list.d/jellyfin.list ]]; then + echo_progress_start "Found old-style '/etc/apt/sources.list.d/jellyfin.list' configuration; removing it." + rm -f /etc/apt/sources.list.d/jellyfin.list + rm -f /etc/apt/keyrings/jellyfin.gpg + echo_progress_done "Removed old repository." + fi + + # + # Add Jellyfin signing key if not already present + if [[ ! -f /etc/apt/keyrings/jellyfin.gpg ]]; then + echo_progress_start "> Did not find signing key. Adding it." + curl -fsSL https://repo.jellyfin.org/jellyfin_team.gpg.key | gpg --dearmor --yes --output /etc/apt/keyrings/jellyfin.gpg + echo_progress_done "Jellyfin Signing Key Added" + fi + # - # install jellyfin and jellyfin-ffmepg using apt functions. + # Install the Deb822 format jellyfin.sources entry + add_jellyfin_repo + # + # Update apt repositories to fetch Jellyfin repository apt_update #forces apt refresh - apt_install jellyfin jellyfin-ffmpeg + + # + # Install Jellyfin and dependencies using apt + # Dependencies are automatically grabbed by apt + apt_install jellyfin + echo_progress_done "Finished updating Jellyfin via apt." + # # Configure the new jellyfin service. + echo_progress_start "Configuring Jellyfin" systemctl -q stop jellyfin.service # # Add the jellyfin user to the master user's group to use our ssl certs. diff --git a/sources/functions/jellyfin b/sources/functions/jellyfin new file mode 100644 index 000000000..d93d74bbf --- /dev/null +++ b/sources/functions/jellyfin @@ -0,0 +1,32 @@ +#!/bin/bash +# Contributers: katiethedev +# This functions file is created to resolve some replicated code between the install and update functions. + +# This function adds the Jellyfin repository. +function add_jellyfin_repo() { + # Set required variables + ARCHITECTURE="$(_os_arch)" + BASE_OS="$(_os_distro)" + case "${BASE_OS}" in + raspbian) + # Raspbian uses the Debian repository + REPO_OS="debian" + ;; + *) + REPO_OS="${BASE_OS}" + VERSION="$(awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release)" + ;; + esac + + # Install the Deb822 format jellyfin.sources entry + echo_progress_start "Adding Jellyfin repository to apt." + cat << EOF | tee /etc/apt/sources.list.d/jellyfin.sources +Types: deb +URIs: https://repo.jellyfin.org/${REPO_OS} +Suites: ${VERSION} +Components: main +Architectures: ${ARCHITECTURE} +Signed-By: /etc/apt/keyrings/jellyfin.gpg +EOF + echo_progress_done "Jellyfin repository added." +}