noket 5 Posted November 11, 2024 Posted November 11, 2024 Sharing is caring as they say.. I'm working towards a "full stack" ubuntu server and this was one of the pieces needed in separating the metadata from the application that'll live in the system image. This script is for more granular control of emby, to ensure the service doesn't start running automatically once the server is booted. For example, if you have a RAID and need to give the RAID a few moments to initialize and mount before you start hammering it with data. You'll want to make sure to change relevant file paths This script will kill any existing emby sessions, download emby from git source, apply the update via dpkg, disable the service that gets automatically added, and then relaunch emby. It relaunches emby by starting a subprocess under a daemon user with limited permissions: #!/bin/bash --login #suggested filename: update-emby.sh #first, get counts for each process emby_pid_count=$(pgrep -ic embyserver) # if emby is running, safely end emby if [[ ! "$emby_pid_count" -eq 0 ]] then emby_pid=$(pgrep -i emby) for i in "${emby_pid[@]}" do echo "$emby_pid" | xargs -n 1 -d "\n" /usr/bin/kill done fi # get the release version from the web # working as of 11/11/2024, if the url/format changes the below syntax may need to be updated owner="MediaBrowser" repo="Emby.Releases" # gets the latest version from the github URL latest_version=` curl https://github.com/$owner/$repo/releases/latest --verbose 2>&1 | grep location: | sed -e "s|.*tag/||" | sed -e "s|\s||"` trimmed_version=${latest_version//[$'\n']/ } echo "version: $latest_version" # if the version number is in the file name, append it # example: # file=somefile-$latest_version.ext # link="https://github.com/$owner/$repo/releases/tags/v$latest_version/$file" link="https://github.com/$owner/$repo/releases/download/$trimmed_version/emby-server-deb_" link+="$trimmed_version" link+="_amd64.deb" #https://github.com/MediaBrowser/Emby.Releases/releases/download/4.8.8.0/emby-server-deb_4.8.8.0_amd64.deb echo "emby server link: $link" echo "running curl to get newest version.." downpath="/root/download/git-latest/emby-server/emby-server_" downpath+="$trimmed_version" downpath+=".deb" #download the file and install it /usr/bin/curl -o "$downpath" -L "$link" /usr/bin/dpkg --install "$downpath" #prevent autostart, still copy the config file over to the default just in case /usr/bin/systemctl disable emby-server /usr/bin/cp /root/script/update/update-emby/emby-server.conf /etc/emby-server.conf # ^^ this .conf path will need to be updated .. the file at /etc/emby-server.conf gets overwritten with each upgrade, so you need to manually copy it over #relaunch emby su [DAEMON USERNAME HERE] -s /bin/bash -c 'export EMBY_DATA=[YOUR DATA PATH HERE] && /opt/emby-server/bin/emby-server' & exit 0 And just in case you don't have or need emby-server.conf (it took some trouble to work this all out, so maybe it'll save time for others). Just be warned that parts of the initscript are outdated, so the paths might be inaccurate: # Override defaults for emby initscript # Double check /etc/systemd/system/multi-user.target.wants/emby-server.service # Running 'systemctl enable emby-server' may be needed # The actual executable currently sits at /opt/emby-server/system/EmbyServer (as of 11/11/2024) # sourced by /etc/init.d/emby-server and /usr/bin/emby-server # installed at /etc/emby-server.conf by the maintainer scripts # # This is a POSIX shell fragment # ## To change the defaults add any of the following settings below the comments ## EMBY_USER=daemon-emby #$EMBY_USER, username to run Emby under, the default is emby EMBY_GROUP=mediasrv #$EMBY_GROUP, server group where Emby user belongs ## EMBY_DIR= #$EMBY_DIR, the location of Emby program files the default is /opt/emby-server/bin/emby-server ## EMBY_BIN= #$EMBY_BIN, full path of MediaBrowser.Server.Mono.exe the default is /usr/lib/emby-server/bin/MediaBrowser.Server.Mono.exe EMBY_DATA=[DATA PATH HERE] #$EMBY_DATA, the location of Emby data, cache, logs, the default is /var/lib/emby ## EMBY_PIDFILE= #$EMBY_PIDFILE, the location of emby.pid, the default is /var/run/emby/emby-server.pid. This is managed by the root, don't mess with this unless you like adding security vulnerabilities. ## EMBY_ADD_OPTS= #$EMBY_ADD_OPTS, additional options to pass to the Emby server executable, beyond ffmpeg, ffprobe and restart #MONO_BIN=/usr/bin/mono #$MONO_BIN, full path of mono binary, the default is /usr/bin/mono-sgen ## MONO_OPTS= #$MONO_OPTS, list of additional options to pass to mono binary ## MONO_ENV= #$MONO_ENV, list of environment variables for running mono binary ## ## EXAMPLE if want to run as different user ## add EMBY_USER=username ## otherwise default emby is used 1
eskimos20 0 Posted June 6, 2025 Posted June 6, 2025 I edited your script and made another with a little more checks. Here is for everyone to use #!/bin/bash # Suggested filename: update-emby.sh set -euo pipefail # Configuration OWNER="MediaBrowser" REPO="Emby.Releases" DOWNLOAD_DIR="/home/eskimos" DEB_ARCH="amd64" # Ensure required commands are available for cmd in curl grep sed dpkg systemctl pgrep; do if ! command -v "$cmd" >/dev/null 2>&1; then echo "Error: '$cmd' is required but not installed." >&2 exit 1 fi done # Get installed Emby version installed_version=$(dpkg-query -W -f='${Version}' emby-server 2>/dev/null || echo "none") # Get latest release version from GitHub latest_version=$(curl -sIL "https://github.com/$OWNER/$REPO/releases/latest" \ | grep -i "^location:" \ | sed -E 's|.*tag/([^[:space:]/]+).*|\1|') if [[ -z "$latest_version" ]]; then echo "Failed to fetch the latest version." exit 1 fi echo "Installed version: $installed_version" echo "Latest version: $latest_version" # Compare versions (skip if already up to date) if [[ "$installed_version" == "$latest_version" ]]; then echo "Emby Server is already up to date." exit 0 fi # Download the .deb package deb_file="emby-server-deb_${latest_version}_${DEB_ARCH}.deb" download_url="https://github.com/$OWNER/$REPO/releases/download/${latest_version}/${deb_file}" download_path="${DOWNLOAD_DIR}/${deb_file}" echo "Downloading Emby Server $latest_version..." curl -L -o "$download_path" "$download_url" # Stop Emby safely if running if pgrep -x embyserver > /dev/null; then echo "Stopping Emby Server..." sudo systemctl stop emby-server.service fi # Install the update echo "Installing Emby Server $latest_version..." sudo dpkg -i "$download_path" # Remove downloaded file after successful installation echo "Cleaning up..." rm -f "$download_path" # Re-enable and start Emby sudo systemctl enable emby-server.service sudo systemctl start emby-server.service echo "Update complete. Emby Server is now at version $latest_version."
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now