Skip to content

Instantly share code, notes, and snippets.

@mikl0s
Created August 29, 2018 20:49
Show Gist options
  • Save mikl0s/c8f1eaf83e5bac5705616eac219fa2b2 to your computer and use it in GitHub Desktop.
Save mikl0s/c8f1eaf83e5bac5705616eac219fa2b2 to your computer and use it in GitHub Desktop.
FreeNAS 11.2+ Plex Media Server jail updater script
#!/usr/local/bin/bash
TMPFOLDER="/tmp/pms-updater"
DATO=`date +%F`
LOCALPLEXVERSION=`ps aux|grep localmedia|awk '{ print $16 }'|head -1`
LATESTPLEXVERSION=`cat 1.json | ./JSON.sh -b|grep 'FreeBSD'|grep version|cut -f2|cut -d"\"" -f2`
DOWNLOADURL=`cat 1.json | ./JSON.sh -b|grep 'FreeBSD'|grep url|cut -f2|cut -d"\"" -f2`
PLEXFILENAME=`cat 1.json | ./JSON.sh -b|grep 'FreeBSD'|grep url|cut -f2|cut -d"\"" -f2|cut -d"/" -f6`
if [ ! -d "$TMPFOLDER" ]; then
mkdir -p $TMPFOLDER
cd $TMPFOLDER
fetch -q https://raw.githubusercontent.com/dominictarr/JSON.sh/master/JSON.sh
chmod +x JSON.sh
fi
mkdir -p $TMPFOLDER/$DATO
cd $TMPFOLDER/$DATO
fetch -q https://plex.tv/api/downloads/1.json
if [ "$LOCALPLEXVERSION" != "$LATESTPLEXVERSION" ]
then
fetch -q -o "PLEXFILENAME" "$DOWNLOADURL"
tar xfj $PLEXFILENAME
cd Pl*
ln -s "Plex Media Server" Plex_Media_Server
ln -s libpython2.7.so.1 libpython2.7.so
cd ..
chown -R plex:plex Pl*
cd /usr/local/share/
service plexmediaserver_plexpass stop
mkdir -p old-plex
mv plexmediaserver_plexpass old-plex/plexmediaserver_plexpass.$DATO
mv /tmp/$DATO/Pl* plexmediaserver_plexpass
service plexmediaserver_plexpass start
echo PMS updated from $LOCALPLEXVERSION to $LATESTPLEXVERSION
cd $TMPFOLDER
rm -rf $DATO
fi
if [ "$LOCALPLEXVERSION" == "$LATESTPLEXVERSION" ]
then
echo PMS is already latest version - $LATESTPLEXVERSION
cd $TMPFOLDER
rm -rf $DATO
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment