Updating Plex?

Status
Not open for further replies.

Arkhen

Explorer
Joined
Mar 21, 2016
Messages
50
Hi

So I just got my first FreeNAS up and running and I'm trying to update to the latest Plex version.
I've tried stopping the Plex plugin and typing in the following in Shell:
pkg update && pkg upgrade multimedia/plexmediaserver

but then I get the following error:
ukzHAuF.png


I might be doing something completely wrong here, so feel free to correct me!

Regards,
Arkhen
 

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
Why are you trying to run that on the freenas OS? You're supposed to run it in the Plex jail.
 

Arkhen

Explorer
Joined
Mar 21, 2016
Messages
50
Why are you trying to run that on the freenas OS? You're supposed to run it in the Plex jail.
Lol that's my bad, here is from the Plex jail:
YiIp4EA.png
 

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
If this is in a Plex plugin, you can't use pkg upgrade as far as I know.
 

Arkhen

Explorer
Joined
Mar 21, 2016
Messages
50

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
Or you can create a new jail, and manually install Plex. That's my preferred method
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
or get this, download into yoru jail and use it to update: https://github.com/mstinaff/PMS_Updater

Last few times I've tried that it doesn't work. It may for a new install, my plex plugin installation is about a year and a half old now.

@Arkhen Run the following in the plex jail and report back on whether or not it works:

1. Login with SSH to your FreeNAS (or alternatively go to shell in WebGUI)
2. type: 'jls' (without ' ' ) and take the note of the # of jail of your Plex installation
3. type: jexec # csh' (where # is the number of the jail noted in last step)
4. type: fetch -o PMS_Updater.sh https://raw.githubusercontent.com/mstinaff/PMS_Updater/master/PMS_Updater.sh
5. type: chmod 755 PMS_Updater.sh
6. type: ./PMS_Updater.sh -u PlexPass_User -p PlexPass_password -a

Or alternately from the freenas GUI open the CLI of the plex jail and do steps 4, 5 and 6.
 

Arkhen

Explorer
Joined
Mar 21, 2016
Messages
50
Last few times I've tried that it doesn't work. It may for a new install, my plex plugin installation is about a year and a half old now.

@Arkhen Run the following in the plex jail and report back on whether or not it works:

1. Login with SSH to your FreeNAS (or alternatively go to shell in WebGUI)
2. type: 'jls' (without ' ' ) and take the note of the # of jail of your Plex installation
3. type: jexec # csh' (where # is the number of the jail noted in last step)
4. type: fetch -o PMS_Updater.sh https://raw.githubusercontent.com/mstinaff/PMS_Updater/master/PMS_Updater.sh
5. type: chmod 755 PMS_Updater.sh
6. type: ./PMS_Updater.sh -u PlexPass_User -p PlexPass_password -a

Or alternately from the freenas GUI open the CLI of the plex jail and do steps 4, 5 and 6.
Step 6 is the same when I'm not a PlexPass user?

I get this error after step 6:
5gtgdsb.png
 
Last edited:

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Ok you can try this but you'll need to do it from an SSH client such as putty. If you try it from the CLI in the FreeNAS GUI the formatting will get screwed up and it won't work. NOTE: This is for updating the plugin for non plex pass members only, this won't work for a Plex Pass installation.

From your Plex jail you're going to remove the file you just downloaded and open a new blank file.

Code:
rm  PMS_Updater.sh
ee PMS_Updater.sh


Now copy the contents below into the blank file exit and save your changes. Once you've done that repeat step six from the directions in my previous post.

Code:
#!/bin/sh

URL="https://plex.tv/downloads"
DOWNLOADPATH="/tmp"
LOGPATH="/tmp"
LOGFILE="PMS_Updater.log"
PMSPARENTPATH="/usr/pbi/plexmediaserver-amd64/share"
PMSLIVEFOLDER="plexmediaserver"
PMSBAKFOLDER="plexmediaserver.bak"
PMSPATTERN="PlexMediaServer-[0-9]*.[0-9]*.[0-9]*.[0-9]*.[0-9]*-[0-9,a-f]*-freebsd-amd64.tar.bz2"
CERTFILE="/usr/local/share/certs/ca-root-nss.crt"
AUTOUPDATE=0
FORCEUPDATE=0
VERBOSE=0
REMOVE=0
LOGGING=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
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. '{ 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 [ ! "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

  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:  $URL $DOWNLOADPATH $PMSPATTERN $VERBOSE $lOGGING
##  MODIFIES: $DOWNLOADURL
##
##  connects to the Plex.tv download site and scrapes for the latest download link
findLatest()
{
  local SCRAPEFILE=`basename $URL`

  webGet "$URL" || exit $?
  echo Searching $URL for $PMSPATTERN ..... | LogMsg -n
  DOWNLOADURL=`grep -o "http*:.*$PMSPATTERN" "$DOWNLOADPATH/$SCRAPEFILE"`
  if [ "x$DOWNLOADURL" = "x" ]; then {
  # DOWNLOADURL is zero length, i.e. nothing matched PMSPATTERN. Error and exit
  echo Could not find a $PMSPATTERN 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 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 start
  echo Done. | LogMsg -f
}

while getopts x."u:p:c:l:d:afvr" 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 ;;
  ?) 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
 

Arkhen

Explorer
Joined
Mar 21, 2016
Messages
50
I have no clue of how to do the above, I'm not that advanced of a user.
 

Arkhen

Explorer
Joined
Mar 21, 2016
Messages
50
Then you probably shouldn't be mucking around in the CLI running commands
Lol right now I can't even set up my users so people have separate users on my network... This is pissing me off on so many levels.. xD
 

ovizii

Patron
Joined
Jun 30, 2014
Messages
435
Look, follow Jailer's steps 1-5 then edit the downloaded file and set this option from
PLEXPASS=1 to PLEXPASS=0

If you're not sure how to edit on the command line, you could install nano, quite a nice editor with:
Code:
pkg install nano 


then edit the file with
Code:
nano PMS_Updater.sh

make your change, then close with CTRL+X and select Y to save

then replace his step 6 with
Code:
./PMS_Updater.sh -pPlexPass_password -a



BUT if this doesn't get you going, you REALLY shouldn't be mucking around with the cli ;-)
 

Arkhen

Explorer
Joined
Mar 21, 2016
Messages
50
Thank you for your help guys. Life is a learning experience and I'll take it with a grain of salt.
One day when I think I'm ready I'll return to this topic and try your suggestions, but for now I'll stay far away from the cli and shells until I know what I'm actually doing, and not just copy/pasting a lot of stuff. :D
 
Status
Not open for further replies.
Top