Skip to content

Instantly share code, notes, and snippets.

@piersolenski
Created April 28, 2020 17:23
Show Gist options
  • Save piersolenski/7b6f23ed268c6032ad1d5807a68ccf54 to your computer and use it in GitHub Desktop.
Save piersolenski/7b6f23ed268c6032ad1d5807a68ccf54 to your computer and use it in GitHub Desktop.
Update Emby
#!/bin/bash
# THIS SCRIPT UPDATES EMBY TO THE LATEST STABLE VERSION
# IF AN UPDATE IS AVAILABLE.
#
# Script must be run as root or with root priveleges
# (like using sudo)
#
# !!! USE AT YOUR OWN RISK !!!
#
# Written by Adam Harbach on Feb 18, 2019 on
# a system running Ubuntu Server 18.04.1 LTS on
# an x64 system. Modify as necssary. Some edits may be required.
#
# ====================================================================
# EDIT ME IF NEEDED!
# --------------------------------------------------------------------
# Set the fileame from GitHub that matches the one you use
# for your system architecture. Replace the version number with VVVV
# (four of the letter "V" in UPPERCASE!).
# The script will replace VVVV with the current version number.
latest_download_filename=emby-server-deb_VVVV_amd64.deb
# Set the url of your server. This script is designed to work on
# the same machine as the server software, and is not configured
# for updating a remote machine, but, if your server is listening
# on a port other than the default 8096, you'll need to change it
# here. DO NOT ADD A TRAILING SLASH! Stop after the port number.
#
# Most users won't need to change this.
server_url=http://localhost:8096
# END EDITS (Unless the main script quits working...)
# ====================================================================
#
# Get latest stable version number.
# Visit the symlink of the latest version, discard the HTML output,
# and print the redirected URL, which will contain the version number,
# feed it into AWK, which will strip off all of the URL except
# the version number (version is last item after all forward
# slashes "/" ).
# Give a timeout period (in seconds) in case the internet is down,
# the script won't hang (-m option)
latest_version=$(curl -Ls -m 30 -o /dev/null -w %{url_effective} \
https://github.com/MediaBrowser/Emby.Releases/releases/latest);
# make sure the connection was successful
if [ $? -ne 0 ]; then
echo "Error checking for latest version. Script exiting."
exit 20
fi;
# Success, continue filtering data from that variable.
latest_version=$(echo "$latest_version" | awk -F "/" '{print $NF}' )
# Set download filename.
# Replace the placeholder in the template with the actual current version number.
latest_download_filename=$(echo $latest_download_filename | sed 's/VVVV/'$latest_version'/')
# Set url of latest version
latest_download_url=https://github.com/MediaBrowser/Emby.Releases/releases/download/$(echo $latest_version)/$(echo $latest_download_filename)
# Set file download path. This is where the new package will go
# and where your package installer (dpkg for debian based linux)
# will be set to find the file.
latest_download_path=/tmp/$(echo $latest_download_filename)
# Get the currently installed version number.
# Load the dashboard, and pull the version number from the <head>
# element. give timeout to curl agian in case emby doesn't respond.
installed_version=$(curl -s -m 10 $(echo $server_url)/web/index.html)
# make sure the connection was successful
if [ $? -ne 0 ]; then
echo "Error checking the currently installed version. Is Emby running?"
echo "Script exiting."
exit 22
fi
# Success, continue getting the version number
installed_version=$(echo "$installed_version" \
| sed -n '/data-appversion=\"/p' \
| awk -F "data-appversion=\"" '{print $2}' \
| sed 's/\".*//')
# see if the latest version is installed (do the versions match?)
if [ $installed_version == $latest_version ] ; then
echo "Emby is up to date."
echo "Installed: $latest_version"
echo
echo "Exiting."
else
echo "Emby update available."
echo "Installed: $installed_version"
echo "Latesst: $latest_version"
echo
echo "Attempting to download update."
# download with a 5 minute timeout period
curl -Ls -o $latest_download_path -m 300 $latest_download_url
# see if download was successful
if [ $? -ne 0 ]; then
#failed
echo
echo "Download failed, cleaning up parital download and exiting."
rm $latest_download_path
exit 30
fi
# success, install
echo
echo "Download success. Installing."
dpkg -i $latest_download_path
# was install successful?
if [ $? -eq 0 ]; then
# fail. clean up download
rm $latest_download_path
# notify
echo
echo
echo "Emby failed to install."
# exit with error
exit 51
fi
# success, remove the installer
rm $latest_download_path
echo
echo
echo "Emby updated to version $latest_version."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment