Jump to content

Auto Update Script on Ubuntu


wiz722

Recommended Posts

It kinda bothered me that the Linux version wouldn't update itself, so I made a script that will check the latest version and installed version of the Emby server, and update it if it's new. It handles the internet going down and such so it doesn't hang. Run it on your own periodically, or set it to run in cron (pipe output to null, though!).

 

Now, my server checks for updates every day at 5:30 am, and installs it if one is available.

 

Run at your own risk. My system is running Ubuntu Server 18.04.1 LTS. Lots of comments are in the script, so edit away as needed.

#!/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
Edited by wiz722
  • Like 3
Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...
  • 2 months later...

A fantastic script.

I'd like to adapt this though to pull down the betas for my installation.

What URL should I use instead of https://github.com/MediaBrowser/Emby.Releases/releases/latest ?

Link to comment
Share on other sites

wizard722

A fantastic script.

 

I'd like to adapt this though to pull down the betas for my installation.

 

What URL should I use instead of https://github.com/MediaBrowser/Emby.Releases/releases/latest ?

 

Thank you!

 

I had to really work to find a symlink for the latest (stable) version. I’ve yet to find one for the latest beta version.

 

Realistically, the script just needs to figure out the version number somehow. I tried to minimize the use of commands that aren’t installed on most systems by default (though, there are ways of checking for them), and since curl is there and it can be instructed to output the final redirected url, it was an elegant option. But, you may need to play with the logic and either mess with the git command (which I’m terrible at except for git clone) to possibly browse the releases or flat out download the releases page and parse it (yuck). If I could run some JavaScript on a downloaded HTML file in the command line, that’d be easy. Hey, it’s Linux, so probably possible, but I don’t know with which programs.

 

I’ll see what I can conjure up.

Link to comment
Share on other sites

wizard722

thanks for the quick response @@wizard722,

 

I've got some free time tonight, and I'll try to dabble with it as well.

 

 

I figured it out.

 

Basically, you replace the first part of the current version check:

latest_version=$(curl -Ls -m 30 -o /dev/null -w %{url_effective} \    
https://github.com/MediaBrowser/Emby.Releases/releases/latest);

With:

latest_version=$(timeout 30s git ls-remote --tags https://github.com/MediaBrowser/Emby.Releases.git);

That will pull a list of ALL the version numbers, including the betas, which we want, but still allows timing out if the internet is down. It’s still unfiltered at this point, like the old command, so we replace the data filtering portion after the if block:

latest_version=$(echo "$latest_version" | awk -F "/" '{print $NF}' )

With:

latest_version=$(echo "$latest_version" | awk '{print $2}' | awk -F "/" '{print $NF}' | sort -V | tail -n 1 )

Which will grab column 2, of the git output, which contains the paths of the tags, which end in the version number. awk instance two will then print the last part of that path to get just the version number, then that list is run through sort in version number mode (so it handles all the decimal places correctly), and finally tail prints just the last line, which is the latest version. Same end result, so the rest of the script runs normally. I tested it and it works, I just added an exit command right before it would install. But, it downloaded just fine, so it will work.

 

 

I’m working on a formal edited script so other less technical users can just change a variable to set whether it grabs the latest stable or latest beta. Besides, I had a couple spelling errors in there. Oops...

Link to comment
Share on other sites

wizard722

Here’s an updated script which supports beta versions. You must have git installed for it to work with beta (git not required for stable versions). The script will tell you and revert to the latest stable version if you enable beta mode but you don’t have git.

 

As before, if you run this as a cron job, pipe the output to /dev/null

 

Enjoy!

#!/bin/bash

# THIS SCRIPT UPDATES EMBY TO THE LATEST STABLE VERSION
# (OR THE LATEST BETA VERSION IF EXPLICITLY ENABLED)
# IF AN UPDATE IS AVAILABLE.
#
# A variable in the top section must be modified if you
# want beta versions.
#
# 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.
#
# Modified on October 10, 2019 by Adam Harbach to
# support beta versions if desired. Beta is off by default, and
# must be explicity enabled in the EDIT ME IF NEEDED section.
#
# ====================================================================
# 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


# Want the latest BETA instead of the latest stable release?
# Set this varialbe to something greater than 0 (zero).
# 
# NOTE: Because the latest beta version number is always higher
# than the latest stable version number, and the script does a
# string comparison of the versions, not a numberical comparison,
# the server will be downgraded to the latest stable version if you
# disable beta, as the latest stable version will not match the
# installed beta version number.
# NOTE 2: you must have git installed to check for the latest beta.
# if beta mode is enabled, then the script will check if you have
# git installed. If you don't have git installed, you'll be
# notified and the script will revert back to stable mode. Just
# install git and rerun the script to fix.
# 
# For the latest stable release, set this to 0.
# For the latest beta release, set this to 1 or higher (doesn't matter).
beta_enabled=0


# END EDITS (Unless the main script quits working...)
# ====================================================================
#
# If beta is enabled, make sure git is installed. Revert to stable
# if git is not installed.
if [ $beta_enabled -gt 0]; then
    if [ `whereis git | sed 's/^git\://'` -eq "" ]; then
        # git is not installed!
        echo "You have beta mode enabled, but checking for the latest"
        echo "beta version requires git."
        echo "Please install git, and rerun the script to check for"
        echo "the latest beta release."
        echo ""
        echo "For now, the script is reverting back to the latest"
        echo "stable release."
        beta_enabled=0;
fi
#
# Get the latest version number. Determine if we need the latest
# stable version or the latest beta version. If beta_enabled is
# greater than zero, then we want the beta. otherwise, get the
# latest stable version.
if [ $beta_enabled -gt 0 ]; then
    # We want the latest beta version. Figure out what it is.
    # First, pull a list of all the tags from the git repository.
    # These will contain all the available version numbers, including
    # betas. But, run it with the timeout command in case the internet
    # is down. Once the list is successfully downloaded, use awk to
    # print the last column, which contains the paths of all the tags,
    # which also happens to include all the version numbers. use awk
    # again to print the version number (everything after the last /).
    # Then, sort the list with sort -V, which handles version numbers
    # properly, then tail to get just the last line, which is the
    # latest version.
    latest_version=$(timeout 30s git ls-remote --tags https://github.com/MediaBrowser/Emby.Releases.git);
    # make sure the connection was successful
    if [ $? -ne 0 ]; then
        echo "Error checking for latest version. Script exiting."
        exit 20
    fi;
    # Success. Continue fitering daa from that varialbe.
    latest_version=$(echo "$latest_version" | awk '{print $2}' | awk -F "/" '{print $NF}' | sort -V | tail -n 1 );
else
    # 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}' );
fi;
# 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 "Latest:    $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 
Edited by wizard722
Link to comment
Share on other sites

  • 3 weeks later...

Wow!

 

great work there!

i'll parse through it a bit later...

 

 

 

I forgot to ask earlier if this worked. I couldn’t fully test it because I didn’t want beta, but since the download process and install is the same, I tested it by throwing an exit statement right before the dpkg command, meaning it would have worked.

Link to comment
Share on other sites

Ooh...I found a horrible bug! It was always checking for beta versions. Oops. I’ll fix that original post instead of making a new one so I don’t confuse people. It’s supposed to only do beta if enabled. The bug is I use the same check in both conditions.

 

Also, somehow I have two accounts on the forum, and I just realized when I tried to edit my own post but couldn’t (I must have been on a different computer). I’m sure this is a ToS violation but I promise it wasn’t intentional. wiz722 and wizard722 are both me. I’ll switch to wiz722 and stick to that, but I’ll switch to wizard722 to edit that post. Any way to change the post owner of all wizard722 posts to wiz722?

Edited by wiz722
Link to comment
Share on other sites

Hi, that's great, thanks for sharing !

Hi @@Luke, how about adding this feature to the server like in the windows version?

 

I think everyone would appreciate an automated way of keeping their server updated.

 

 

Thanks!

Link to comment
Share on other sites

it would be amazing if the program could be added to the software repositories. Then apt and yum could take care of updating it. Just have two packages, one called something like emby-media-server and the other emby-media-server-beta.

Link to comment
Share on other sites

ulrick65

Nice job on this.  I assume this has to be run with SUDO, just wanted to make sure that is correct?

 

There is another user here, @@shokinn that made something similar when the repository went dead a while back.  He has since converted it to Python and made some updates.  It can pull either the current or beta as well.

 

See the last post he made here:  https://emby.media/community/index.php?/topic/55030-ubuntu-repository-for-install/?p=693674

 

And here's a link to his github:  https://github.com/shokinn/emby-updater

 

He has it available either a GIT pull, a downloadable executable python file or some other ways I have not played with.

 

Just thought I would share this in case they are of value to someone...works great and I have been using it for quite a while now.  I don't know if many know about it given that I only that one post mentions it.

 

Thanks.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
schmitty

it would be amazing if the program could be added to the software repositories. Then apt and yum could take care of updating it. Just have two packages, one called something like emby-media-server and the other emby-media-server-beta.

 

It used to, but the devs in their infinite wisdom decided to make it manual install only. One of the worst decisions they've ever made... along with removing portable installations, so you can no longer run beta and stable versions side-by-side.

 

@@Luke @@ebr please add Emby Server back to apt, and reintroduce portable installs.

Edited by schmitty
Link to comment
Share on other sites

@@wiz722 how do you pipe the script to null for use in cron?

 

put a redirect ( a greater than sign “>” ) to write to a file. Then, send it to the special file /dev/null, or if you actually want to save the output somewhere to review later, use a file on your file system ( like /home/username/log.txt ).

 

additionally, you’ll need to pipe error messages also. You can either redirect the errors to standard output ( which by now is also going to a file or null ) or redirect errors to a separate file. Use 2, the error console, and redirect it. To merge it with standard output, do 2>&1.

 

Examples:

Drop any and all output

update-emby.sh > /dev/null 2>&1

 

keep a log file , and put all errors in the same log file, too ( always use a full path, not a relative one. Also, adjust the folder to a real one)

update-emby.sh > /home/someuser/log.txt 2>&1

 

keep a log and error messages in separate files ( again, use real folders on your system)

update-emby.sh > /home/someuser/log.txt 2>/home/someuser/error.txt

 

keep a log but discard errors

update-emby.sh > /home/someuser/log.txt 2>/dev/null

 

this is true of any command, actually. It’s a little bit intermediate shell scripting, but that’s the basic idea.

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
RedBaron164

I was having some issues with getting the script to run successfully via cron. I thought I'd share what I ended up using in case anyone else has any issues.

0 5 * * * /scripts/emby-updater.sh > "/scripts/update-log-`date '+\%Y-\%m-\%d_\%H\%M'`.log" 2>&1

This way the script runs every morning at 5am and will generate a log file with the current date and time. The log file will include the output of the script which is currently this:
 

Emby is up to date.
Installed: 4.3.0.30
 
Exiting.

Now I just need to wait for the next release to ensure it works properly.
  • Like 1
Link to comment
Share on other sites

  • 3 months later...
Hekmon

Very nice, thank you !

 

But there is something I don't get:

    # 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

Shouldn't it be

    # was install successful?
    if [ $? -ne 0 ]; then
        # fail. clean up download

 instead ?

 

Here is my patch

--- update_emby.sh      2020-04-09 12:57:43.475511917 +0200
+++ update_emby_fixed.sh        2020-04-09 12:59:30.991484310 +0200
@@ -94,7 +94,7 @@
 else
     echo "Emby update available."
     echo "Installed: $installed_version"
-    echo "Latesst:   $latest_version"
+    echo "Latest:    $latest_version"
     echo
     echo "Attempting to download update."
     # download with a 5 minute timeout period
@@ -111,15 +111,16 @@
     echo
     echo "Download success. Installing."
     dpkg -i $latest_download_path
+    result=$?

     # was install successful?
-    if [ $? -eq 0 ]; then
+    if [ $result -ne 0 ]; then
         # fail. clean up download
         rm $latest_download_path
         # notify
         echo
         echo
-        echo "Emby failed to install."
+        echo "Emby failed to install (dpkg exit code $result)"
         # exit with error
         exit 51
     fi

You can find the complete script attached :)

(I was not allowed to upload a .sh file so it is in a .txt format)

update_emby_fixed.txt

Link to comment
Share on other sites

  • 4 months later...
#!/bin/bash
# THIS SCRIPT UPDATES EMBY TO THE LATEST STABLE VERSION
# (OR THE LATEST BETA VERSION IF EXPLICITLY ENABLED)
# IF AN UPDATE IS AVAILABLE.
#
# A variable in the top section must be modified if you
# want beta versions.
#
# 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.
#
# Modified on October 10, 2019 by Adam Harbach to
# support beta versions if desired. Beta is off by default, and
# must be explicity enabled in the EDIT ME IF NEEDED section.
#
# ====================================================================
# 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


# Want the latest BETA instead of the latest stable release?
# Set this varialbe to something greater than 0 (zero).
# 
# NOTE: Because the latest beta version number is always higher
# than the latest stable version number, and the script does a
# string comparison of the versions, not a numberical comparison,
# the server will be downgraded to the latest stable version if you
# disable beta, as the latest stable version will not match the
# installed beta version number.
# NOTE 2: you must have git installed to check for the latest beta.
# if beta mode is enabled, then the script will check if you have
# git installed. If you don't have git installed, you ll be
# notified and the script will revert back to stable mode. Just
# install git and rerun the script to fix.
# 
# For the latest stable release, set this to 0.
# For the latest beta release, set this to 1 or higher (doesn't matter).
beta_enabled=1


# END EDITS (Unless the main script quits working...)
# ====================================================================
#
# If beta is enabled, make sure git is installed. Revert to stable
# if git is not installed.
#if [ $beta_enabled -gt 0 ]; then
#    if [ `whereis git | sed 's/^git\://'` -eq "" ]; then
        # git is not installed!
#        echo "You have beta mode enabled, but checking for the latest"
#        echo "beta version requires git."
#        echo "Please install git, and rerun the script to check for"
#        echo "the latest beta release."
#        echo ""
#        echo "For now, the script is reverting back to the latest"
#        echo "stable release."
#        beta_enabled=0;
#    fi
#fi
#
# Get the latest version number. Determine if we need the latest
# stable version or the latest beta version. If beta_enabled is
# greater than zero, then we want the beta. otherwise, get the
# latest stable version.
if [ $beta_enabled -gt 0 ]; then
    # We want the latest beta version. Figure out what it is.
    # First, pull a list of all the tags from the git repository.
    # These will contain all the available version numbers, including
    # betas. But, run it with the timeout command in case the internet
    # is down. Once the list is successfully downloaded, use awk to
    # print the last column, which contains the paths of all the tags,
    # which also happens to include all the version numbers. use awk
    # again to print the version number (everything after the last /).
    # Then, sort the list with sort -V, which handles version numbers
    # properly, then tail to get just the last line, which is the
    # latest version.
    latest_version=$(timeout 30s git ls-remote --tags https://github.com/MediaBrowser/Emby.Releases.git);
    # make sure the connection was successful
    if [ $? -ne 0 ]; then
        echo "Error checking for latest version. Script exiting."
        exit 20
    fi;
    # Success. Continue fitering daa from that varialbe.
    latest_version=$(echo "$latest_version" | awk '{print $2}' | awk -F "/" '{print $NF}' | sort -V | tail -n 1 );
else
    # 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}' );
fi;
# 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 "Latest:    $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
        # success, remove the installer
        rm $latest_download_path
        # notify
        echo
        echo
        echo "Emby updated to version $latest_version."
        # exit with error
        exit 51
    fi
    # error happend
    rm $latest_download_path
    echo
    echo
    echo "Emby failed to install."
fi
exit 0 

in my case i had to modify the script in order to work properly this is the modified version which is going on beta chanel. 

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

With a couple of edits and I was able to use this in a BSD jail, and automate with crontab

You may need to install bash, curl, and/or git

#!/bin/bash
# THIS SCRIPT UPDATES EMBY TO THE LATEST STABLE VERSION
# (OR THE LATEST BETA VERSION IF EXPLICITLY ENABLED)
# IF AN UPDATE IS AVAILABLE.
#
# A variable in the top section must be modified if you
# want beta versions.
#
# 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.
#
# Modified on October 10, 2019 by Adam Harbach to
# support beta versions if desired. Beta is off by default, and
# must be explicity enabled in the EDIT ME IF NEEDED section.
#
# ====================================================================
# 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-freebsd12_VVVV_amd64.txz 


# 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


# Want the latest BETA instead of the latest stable release?
# Set this varialbe to something greater than 0 (zero).
# 
# NOTE: Because the latest beta version number is always higher
# than the latest stable version number, and the script does a
# string comparison of the versions, not a numberical comparison,
# the server will be downgraded to the latest stable version if you
# disable beta, as the latest stable version will not match the
# installed beta version number.
# NOTE 2: you must have git installed to check for the latest beta.
# if beta mode is enabled, then the script will check if you have
# git installed. If you don't have git installed, you ll be
# notified and the script will revert back to stable mode. Just
# install git and rerun the script to fix.
# 
# For the latest stable release, set this to 0.
# For the latest beta release, set this to 1 or higher (doesn't matter).
beta_enabled=1


# END EDITS (Unless the main script quits working...)
# ====================================================================
#
# If beta is enabled, make sure git is installed. Revert to stable
# if git is not installed.
#if [ $beta_enabled -gt 0 ]; then
#    if [ `whereis git | sed 's/^git\://'` -eq "" ]; then
        # git is not installed!
#        echo "You have beta mode enabled, but checking for the latest"
#        echo "beta version requires git."
#        echo "Please install git, and rerun the script to check for"
#        echo "the latest beta release."
#        echo ""
#        echo "For now, the script is reverting back to the latest"
#        echo "stable release."
#        beta_enabled=0;
#    fi
#fi
#
# Get the latest version number. Determine if we need the latest
# stable version or the latest beta version. If beta_enabled is
# greater than zero, then we want the beta. otherwise, get the
# latest stable version.
if [ $beta_enabled -gt 0 ]; then
    # We want the latest beta version. Figure out what it is.
    # First, pull a list of all the tags from the git repository.
    # These will contain all the available version numbers, including
    # betas. But, run it with the timeout command in case the internet
    # is down. Once the list is successfully downloaded, use awk to
    # print the last column, which contains the paths of all the tags,
    # which also happens to include all the version numbers. use awk
    # again to print the version number (everything after the last /).
    # Then, sort the list with sort -V, which handles version numbers
    # properly, then tail to get just the last line, which is the
    # latest version.
    latest_version=$(timeout 30s git ls-remote --tags https://github.com/MediaBrowser/Emby.Releases.git);
    # make sure the connection was successful
    if [ $? -ne 0 ]; then
        echo "Error checking for latest version. Script exiting."
        exit 20
    fi;
    # Success. Continue fitering daa from that varialbe.
    latest_version=$(echo "$latest_version" | awk '{print $2}' | awk -F "/" '{print $NF}' | sort -V | tail -n 1 );
else
    # 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}' );
fi;
# 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 "Latest:    $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."
    pkg add -f $latest_download_path
    # was install successful?
    if [ $? -eq 0 ]; then
        # success, remove the installer
        rm $latest_download_path
        # notify
        echo
        echo
        echo "Emby updated to version $latest_version."
        # exit with error
        exit 51
    fi
    # error happend
    rm $latest_download_path
    echo
    echo
    echo "Emby failed to install."
fi
exit 0 

 

Edited by avgsmoe
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...