Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.

How to Update Plex Manually in FreeNAS 11.2 iocage jail

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
599
The ports tree is great but sometimes can take awhile to update to the latest version. I use the web version of plex alot and the update nagging forced me to figure this out. I discovered there is no other good tutorial to accomplish this. So here you have it.

First you want to be ssh'd into your FreeNAS Host. Use putty or your favorite terminal to do this. Then we enter the plex jail..
Code:
##Find your plex jail number##
jls
##Enter Plex Jail##
jexec # csh


You need to have wget and nano installed so..
pkg install nano wget

Then for ease switch to your PMS directory, for me this is /usr/local/plexdata-plexpass but for you it may be /usr/local/plexdata or something..
cd /usr/local/plexdata-plexpass

Then we need to get the latest version of Plex from the plex.tv website, https://www.plex.tv/media-server-downloads/ at the time of this writing its 1.13.9.5439. Select FreeBSD, right click the download button and select "copy link address".

Then at the Plex jail's terminal do..
wget <paste the above copied link here>


Then we get the script. Big thanks to mstinaff over at github.

As it stands its written to only update the plugin version (PBI) so we update it for our use. This is where you need to know if you have standard (plexmediaserver) or (plexmediaserver_plexpass) installed. You probably already know which version you have. Do...
nano PMS_Updater.sh

Paste in this script. Its set for the plexpass version. If you dont have plexpass, search and replace instances of plexmediaserver-plexpass and plexmediaserver_plexpass with just plexmediaserver.
Code:
#!/bin/sh

URLBASIC="https://plex.tv/api/downloads/1.json"
URLPLEXPASS="https://plex.tv/api/downloads/1.json?channel=plexpass"
DOWNLOADPATH="/tmp"
LOGPATH="/tmp"
LOGFILE="PMS_Updater.log"
PMSPARENTPATH="/usr/local/share"
PMSLIVEFOLDER="plexmediaserver-plexpass"
PMSBAKFOLDER="plexmediaserver-plexpass.bak"
CERTFILE="/usr/local/share/certs/ca-root-nss.crt"
AUTOUPDATE=0
FORCEUPDATE=0
VERBOSE=0
REMOVE=0
LOGGING=1
PLEXPASS=1

# Initialize CURRENTVER to the script max so if reading the current version fails
# for some reason we don't blindly clobber things
CURRENTVER=9999.9999.9999.9999.9999


usage()
{
cat << EOF
usage: $0 options
This script will search the plex.tv download site for a download link
and if it is newer than the currently installed version the script will
download and optionaly install the new version.
OPTIONS:
   -u      PlexPass username
             If -u is specified without -p then the script will
             prompt the user to enter the password when needed
   -p      PlexPass password
   -c      PlexPass user/password file
             When wget is run with username and password on the
             command line, that information is displayed in the
             process list for all to see.  A more secure method
             is to create a file readable only by root that is
             formatted like this:
               user={Your Username Here}
               password={Your Password Here}
   -l      Local file to install instead of latest from Plex.tv
   -d      download folder (default /tmp) Ignored if -l is used
   -a      Auto Update to newer version
   -f      Force Update even if version is not newer
   -r      Remove update packages older than current version
             Done before any update actions are taken.
   -v      Verbose
   -n      Use normal version (not PlexPass) version
EOF
}

##  LogMsg()
##  READS:     STDIN (Piped input) $1 (passed in string) $LOGPATH $LOGFILE
##  MODIFIES:  NONE
##
##  Writes log entries to $LOGGINGPATH/$LOGGINGFILE
LogMsg()
{
    if [ "$1" = "-n" ]; then SWITCH="-n"; fi
    while read IN; do
      tdStamp=`date +"%Y-%m-%d %H:%M.%S"`
      if [ $LOGGING = 1 ]; then echo "$tdStamp  $IN" >> $LOGPATH/$LOGFILE; fi
      if [ $VERBOSE = 1 ] || [ "$1" = "-f" ]; then echo $SWITCH $IN; fi
    done
}




##  verNum()
##  READS:    $1 (passed in string)
##  MODIFIES: NONE
##
##  Converts the Plex version string to a mathmatically comparable
##      number by removing non numericals and padding each section with zeros
##      so v0.9.9.10.485 becomes 00000009000900100485
verNum()
{
    echo "$@" | awk -F '[^0-9]+' '{ printf("%04d%04d%04d%04d%04d", $1,$2,$3,$4,$5)}'
}


##  removeOlder()
##  READS:    $DOWNLOADPATH $PMSPATTERN $CURRENTVER $VERBOSE $LOGGING
##  MODIFIES: NONE
##
##  Searches $DOWNLOADPATH for PMS install packages and removes versions older
##  than $CURRENTVER
removeOlder()
{
    for FOUNDINSTALLFILE in `ls $DOWNLOADPATH/$PMSPATTERN`
    do {
        if [ $(verNum `basename $FOUNDINSTALLFILE`) -lt $(verNum $CURRENTVER) ]; then {
            echo Removing $FOUNDINSTALLFILE | LogMsg
            rm -f $FOUNDINSTALLFILE 2>&1 | LogMsg
        } fi
    } done
}


##  webGet()
##  READS:    $1 (URL) $DOWNLOADPATH $USERPASSFILE $USERNAME $PASSWORD $VERBOSE $LOGGING
##  MODIFIES: NONE
##
##  invoke wget with configured account info
webGet()
{
    local LOGININFO=""
    local QUIET="--quiet"

    if [ $PLEXPASS = 1 ]; then
      if [ ! "x$USERPASSFILE" = "x" ] && [ -e $USERPASSFILE ]; then
          LOGININFO="--config=$USERPASSFILE"
      elif [ ! "x$USERNAME" = "x" ]; then
          if [ "x$PASSWORD" = "x" ]; then
              LOGININFO="--http-user=$USERNAME --ask-password"
          else
              LOGININFO="--http-user=$USERNAME --http-password=$PASSWORD"
          fi
      fi
    fi

    if [ $VERBOSE = 1 ]; then QUIET=""; fi
    echo Downloading $1 | LogMsg
    wget $QUIET $LOGININFO --auth-no-challenge --ca-certificate=$CERTFILE --timestamping --directory-prefix="$DOWNLOADPATH" "$1"
    if [ $? -ne 0 ]; then
        echo Error downloading $1
        exit 1
    else
        echo Download Complete | LogMsg
    fi
}


##  findLatest()
##  READS:    $URLBASIC $URLPLEXPASS $DOWNLOADPATH $PMSPATTERN $VERBOSE $lOGGING
##  MODIFIES: $DOWNLOADURL
##
##  connects to the Plex.tv download site and scrapes for the latest download link
findLatest()
{
    if [ $PLEXPASS = 1 ]; then local URL=$URLPLEXPASS; else local URL=$URLBASIC; fi
    if [ $VERBOSE = 1 ]; then echo Using URL $URL; fi
    local SCRAPEFILE=`basename $URL`

    webGet "$URL" || exit $?
        echo Searching $URL for the FreeBSD download URL ..... | LogMsg -n
    DOWNLOADURL=`cat $DOWNLOADPATH/$SCRAPEFILE | perl -MJSON::PP -E 'say decode_json(<STDIN>)->{computer}{FreeBSD}{releases}[0]{url}'`
    if [ "x$DOWNLOADURL" = "x" ]; then {
        # DOWNLOADURL is zero length, i.e. nothing matched PMSPATTERN. Error and exit
        echo Could not find a FreeBSD download link on page $URL | LogMsg -f
        exit 1
    } else {
        echo Done. | LogMsg -f
    } fi
}


##  applyUpdate()
##  READS:    $PMSPARENTPATH $PMSLIVEFOLDER $PMSBAKFOLDER $LOCALINSTALLFILE $VERBOSE $LOGGING
##  MODIFIES: NONE
##
##  Removes anything in the specified backup location, stops
##    Plex, moves the current to backup, then tries to extract the new zip
##    to the live location.  If there is an error while unpacking the files
##    are deleted and the backup is moved back.  Plex is then started.
##    It could be possible to check status after starting a new plex and
##    rolling back if it does not start, should check that it is running
##    properly before hand to avoid constantly trying to update a broken
##    install
applyUpdate()
{

    echo Removing previous PMS Backup ..... | LogMsg -n
    rm -rf $PMSPARENTPATH/$PMSBAKFOLDER 2>&1 | LogMsg
    echo Done. | LogMsg -f
    echo Stopping Plex Media Server .....| LogMsg -n
    service plexmediaserver_plexpass stop 2>&1 | LogMsg
    echo Done. | LogMsg -f
    echo Moving current Plex Media Server to backup location .....| LogMsg -n
    mv $PMSPARENTPATH/$PMSLIVEFOLDER/ $PMSPARENTPATH/$PMSBAKFOLDER/ 2>&1 | LogMsg
    echo Done. | LogMsg -f
    echo Extracting $LOCALINSTALLFILE .....| LogMsg -n
    mkdir $PMSPARENTPATH/$PMSLIVEFOLDER/ 2>&1 | LogMsg
    tar -xj --strip-components 1 --file $LOCALINSTALLFILE --directory $PMSPARENTPATH/$PMSLIVEFOLDER/ 2>&1 | LogMsg -f
    if [ $? -ne 0 ]; then {
        echo Error exctracting $LOCALINSTALLFILE. Rolling back to previous version. | LogMsg -f
        rm -rf $PMSPARENTPATH/$PMSLIVEFOLDER/ 2>&1 | LogMsg -f
        mv $PMSPARENTPATH/$PMSBAKFOLDER/ $PMSPARENTPATH/$PMSLIVEFOLDER/ 2>&1 | LogMsg -f
    } else {
        echo Done. | LogMsg -f
    } fi
    ln -s $PMSPARENTPATH/$PMSLIVEFOLDER/Plex\ Media\ Server $PMSPARENTPATH/$PMSLIVEFOLDER/Plex_Media_Server 2>&1 | LogMsg
    ln -s $PMSPARENTPATH/$PMSLIVEFOLDER/libpython2.7.so.1 $PMSPARENTPATH/$PMSLIVEFOLDER/libpython2.7.so 2>&1 | LogMsg
    echo Starting Plex Media Server .....| LogMsg -n
    service plexmediaserver_plexpass start
    echo Done. | LogMsg -f
}

while getopts x."u:p:c:l:d:afvrn" OPTION
do
     case $OPTION in
         u) USERNAME=$OPTARG ;;
         p) PASSWORD=$OPTARG ;;
         c) USERPASSFILE=$OPTARG ;;
         l) LOCALINSTALLFILE=$OPTARG ;;
         d) DOWNLOADPATH=$OPTARG ;;
         a) AUTOUPDATE=1 ;;
         f) FORCEUPDATE=1 ;;
         v) VERBOSE=1 ;;
         r) REMOVE=1 ;;
         n) PLEXPASS=0 ;;
         ?) usage; exit 1 ;;
     esac
done

# Get the current version
CURRENTVER=`export LD_LIBRARY_PATH=$PMSPARENTPATH/$PMSLIVEFOLDER; $PMSPARENTPATH/$PMSLIVEFOLDER/Plex\ Media\ Server --version`
if [ $REMOVE = 1 ]; then removeOlder; fi

if [ "x$LOCALINSTALLFILE" = "x" ]; then {
    #  No local source provided, check the web
    findLatest || exit $?
    if [ $FORCEUPDATE = 1 ] || [ $(verNum `basename $DOWNLOADURL`) -gt $(verNum $CURRENTVER) ]; then {
        webGet "$DOWNLOADURL"  || exit $?
        LOCALINSTALLFILE="$DOWNLOADPATH/`basename $DOWNLOADURL`"
    } else {
        echo Already running latest version $CURRENTVER | LogMsg
                exit
    } fi
} elif [ ! $FORCEUPDATE = 1 ] &&  [ $(verNum `basename $LOCALINSTALLFILE`) -le $(verNum $CURRENTVER) ]; then {
    echo Already running version $CURRENTVER | LogMsg
    echo Use -f to force install $LOCALINSTALLFILE | LogMsg
    exit
} fi


# If either update flag is set then verify archive integrity and install
if [ $FORCEUPDATE = 1 ] || [ $AUTOUPDATE = 1 ]; then {
        echo Verifying $LOCALINSTALLFILE ..... | LogMsg -n
    bzip2 -t $LOCALINSTALLFILE
    if [ $? -ne 0 ]; then {
        echo $LOCALINSTALLFILE is not a valid archive, cannot update with this file. | LogMsg -f
    } else {
        echo Done | LogMsg -f
        applyUpdate
    } fi
} fi


Then do CTRL+X, enter, enter to Save file and exit NANO.

Then we make our script executable by
chmod +x PMS_Updater.sh

Now its time for the magic, run the command, take care to make the proper edits. Include your plex.tv login credentials if you have plexpass.
./PMS_Updater.sh -u USERNAME -p PASSWORD -vv -a

AS TIME GOES ON THIS COMMAND WILL CHANGE WITH PLEX VERSIONS. Substitute whatever .tar.bz file was download above. Look by doing a ls and use that filename to complete the above command.

You should now have the latest version not yet in the ports tree.

Cheers hope this helps you!
 
Last edited:

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,346
All that trouble to get the latest version of plex what, a week sooner?

I don't get it.......
 

pschatz100

Neophyte Sage
Joined
Mar 30, 2014
Messages
907
This is a very complicated way to perform what ought to be a relatively simple task... and it is only good for Warden jails. The problem is that Warden jails have been EOL'd.

I suggest anybody who wants to install and manage Plex manually, do so in an iocage jail. But do not use the UI in the beta releases. Use the Shell. This would be a very good reason to learn how to use iocage.
 

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
599
If you dont mind waiting, then wait. This post is clearly not for you. This particular Plex version clearly doesnt do anything major but what about in the future? I decided to learn how to do it and thought others might want to know as well. Thats all this is.

Also I am using iocage, i just go about it in the more traditional way. This does work just fine in an iocage jail.
 

pschatz100

Neophyte Sage
Joined
Mar 30, 2014
Messages
907
Well, each to his own. However, this procedure is way more complicated than it needs to be and is not using iocage tools that exist for this purpose. It has nothing to do with waiting...

Some diligent searching will turn up simpler ways to accomplish the same task.
 

Stookdog

Neophyte
Joined
Oct 19, 2018
Messages
4
Idk what's up w/ the negative comments, if you don't have use for what he's sharing then just move on. I personally found this super helpful and thanks to you am currently running the most updated version of PMS. I looked at many articles/posts and none were able to get to me to the latest update of Plex (not even to updates that were released over a month ago). The pkg update and pkg upgrade were several versions behind and it was bugging me to keep seeing that I was out of date. Again, thank you for the clear guide!
 

pschatz100

Neophyte Sage
Joined
Mar 30, 2014
Messages
907
Idk what's up w/ the negative comments, if you don't have use for what he's sharing then just move on. I personally found this super helpful and thanks to you am currently running the most updated version of PMS. I looked at many articles/posts and none were able to get to me to the latest update of Plex (not even to updates that were released over a month ago). The pkg update and pkg upgrade were several versions behind and it was bugging me to keep seeing that I was out of date. Again, thank you for the clear guide!
I'm glad the OP's procedure worked for you. I was only pointing out there's little point in using complicated workflows to do simple things. In this particular case, the workflow also involves installing some extra software which is not necessary for the purpose. And, of course, it will have to be maintained

For many people, this makes the task more complex than it needs to be and often creates problems down the road. I like to be current too. If you found that the pkg system was several versions out of date, then perhaps it would be wise to learn more about how the pkg system works.
 
Last edited:

hoserama

Member
Joined
Dec 24, 2017
Messages
25
thanks op!

People may be able to get around adding Nano by using ee - i believe it comes already installed.

This works perfect and is exactly what i was looking for.
 

smiti

Newbie
Joined
Mar 24, 2018
Messages
1
This worked perfectly for me. I was able to just plug the script in with no file download or version specification. Just copy, paste, run.

Thank you!
 

stillka

Member
Joined
Nov 15, 2014
Messages
28
Hi,
here is manual way of update:

- stop plex jail, go to program dir, in my case: cd /mnt/iocage/jails/plex/root/usr/local/share/

- rename old plexmediaserver version to "plexmediaserver.old": mv plexmediaserver plexmediaserver.old

- download latest freebsd release to that dir (/mnt/iocage/jails/plex/root/usr/local/share/) and un-compress:
tar xvjf PlexMediaServer-1.14.0.5470-9d51fdfaa-freebsd-amd64.tar.bz2

- rename created folder to "plexmediaserver": mv PlexMediaServer-1.14.0.5470-9d51fdfaa plexmediaserver

- set right owner permissions like old directory have, in my case: chown -R root:wheel plexmediaserver

- go to plexmediaserver dir and re-create missing symlinks: cd plexmediaserver/lib; ln -s libpython2.7.so.1 libpython2.7.so;
cd ..; ln -s Plex\ Media\ Server Plex_Media_Server

- Finish, you can start your jail up.
 
Last edited:

MrMcLargeHuge

Junior Member
Joined
Jan 28, 2014
Messages
13
Thanks OP. I'm still running warden, and pkg update is no longer a viable option because of the old template. My Plex install was beginning to get out of date. I'm anticipating headaches with the migration to iocage, so I'm trying to delay it for a bit. This worked perfectly. Great stopgap solution.
 

bloodyfire6000

Neophyte
Joined
Jan 2, 2019
Messages
5
hey OP, I kinda need help in doing this process. How do I get the nano, my plex keeps saying that it is not there or not in the repo.
 
Joined
Aug 3, 2018
Messages
6
Hello John Digital I tried your steps above and everything install, but my plex server still saying that I am on version 1.14.1.5488. Also, I tried to rerun the steps and it is telling that I am already on Version 1.15.2

1553299836661.png
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,346
Clear your web browser cache.
 

Yummiesttag

Junior Member
Joined
Mar 7, 2018
Messages
22
Hi,
here is manual way of update:

- stop plex jail, go to program dir, in my case: cd /mnt/iocage/jails/plex/root/usr/local/share/

- rename old plexmediaserver version to "plexmediaserver.old": mv plexmediaserver plexmediaserver.old

- download latest freebsd release to that dir (/mnt/iocage/jails/plex/root/usr/local/share/) and un-compress:
tar xvjf PlexMediaServer-1.14.0.5470-9d51fdfaa-freebsd-amd64.tar.bz2

- rename created folder to "plexmediaserver": mv PlexMediaServer-1.14.0.5470-9d51fdfaa plexmediaserver

- set right owner permissions like old directory have, in my case: chown -R root:wheel plexmediaserver

- go to plexmediaserver dir and re-create missing symlinks: cd plexmediaserver; ln -s libpython2.7.so.1 libpython2.7.so; ln -s Plex\ Media\ Server Plex_Media_Server

- Finish, you can start your jail up.
Upon following these steps, I get this message when going to settings on plex.
Code:
Server settings are unavailable.
 

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
599
Code:
./PMS_Updater.sh -u USERNAME -p PASSWORD -vv -a
This is once again all that is need once you have the script made. I just did an update with it to try and get rid of the "no soup for you" bug. Its still doing it, and also has double the amount of currently playing streams.. Strange..

hey OP, I kinda need help in doing this process. How do I get the nano, my plex keeps saying that it is not there or not in the repo.
Sorry I have been unreachable. You can just do pkg install nano
 

John Digital

Neophyte Sage
Joined
Jan 7, 2015
Messages
599
Upon following these steps, I get this message when going to settings on plex.
Code:
Server settings are unavailable.
The directory should likely not be owned by root.
 
Top