Updater-plex.sh
· 2.0 KiB · Bash
Surowy
#!/bin/bash
#####
#
# This Script will update Plex Media Server to the latest version for Debian/Ubuntu
#
# To automatically check & update plex, run "crontab -e" and add the following lines
#
# # Check for Plex Media Server Updates every day @6:00 am
# 0 6 * * * /root/update-plexmediaserver.sh
#
# 2018 - Original by Matthieu Guerry
# - Customised by erreur32
###
# Check Current installed version and exit if latest is already installed
service=plex
VersionInstalled=$(dpkg -s plexmediaserver | grep -Po '(?<=Version\: )(\S+)')
VersionAvailable=$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu" | grep -Po '(?<=(\" version=\"))(\S+)(?=(\"))')
echo -e " Checking Plex version ... "
echo -e " Version installed = $VersionInstalled"
echo -e " Version Available = $VersionAvailable"
if [[ -z $VersionInstalled ]]; then echo " Plex is not installed - exit "; exit; fi
if [ $VersionAvailable = $VersionInstalled ]; then echo "Plex Media Server is already up-to-date (version $VersionInstalled) ... Bye! "; exit; fi
echo -e " Download new Version $VersionAvailable"
# Download latest installation package to /tmp folder
curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu" | grep -Po '(?<=url=\")(\S+)(?=\")' | xargs wget -P /tmp/
if [[ -z $(ps -ef |grep ${service}) ]]
then
print "Hum service down !?! , anyway Service will updating\n"
else
print "Plex is running, service will stop before Update...\n"
fi
# Stop Plex Service
sudo service plexmediaserver stop
# Install latest version
sudo dpkg -i /tmp/$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu" | grep -Po '(?<=fileName=\")(\S+)(?=\")')
ps -ef | grep plex | grep -v grep
[ $? -eq "0" ] && echo "Plex is running back :)" || echo "Plex is not running ... ;("
# Start Plex Service
echo -e " restart service Plex"
sudo service plexmediaserver start
# Remove installation package from /tmp folder
rm /tmp/plexmediaserver_*
| 1 | #!/bin/bash |
| 2 | |
| 3 | ##### |
| 4 | # |
| 5 | # This Script will update Plex Media Server to the latest version for Debian/Ubuntu |
| 6 | # |
| 7 | # To automatically check & update plex, run "crontab -e" and add the following lines |
| 8 | # |
| 9 | # # Check for Plex Media Server Updates every day @6:00 am |
| 10 | # 0 6 * * * /root/update-plexmediaserver.sh |
| 11 | # |
| 12 | # 2018 - Original by Matthieu Guerry |
| 13 | # - Customised by erreur32 |
| 14 | ### |
| 15 | |
| 16 | # Check Current installed version and exit if latest is already installed |
| 17 | service=plex |
| 18 | VersionInstalled=$(dpkg -s plexmediaserver | grep -Po '(?<=Version\: )(\S+)') |
| 19 | VersionAvailable=$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu" | grep -Po '(?<=(\" version=\"))(\S+)(?=(\"))') |
| 20 | echo -e " Checking Plex version ... " |
| 21 | echo -e " Version installed = $VersionInstalled" |
| 22 | echo -e " Version Available = $VersionAvailable" |
| 23 | |
| 24 | if [[ -z $VersionInstalled ]]; then echo " Plex is not installed - exit "; exit; fi |
| 25 | if [ $VersionAvailable = $VersionInstalled ]; then echo "Plex Media Server is already up-to-date (version $VersionInstalled) ... Bye! "; exit; fi |
| 26 | |
| 27 | echo -e " Download new Version $VersionAvailable" |
| 28 | # Download latest installation package to /tmp folder |
| 29 | curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu" | grep -Po '(?<=url=\")(\S+)(?=\")' | xargs wget -P /tmp/ |
| 30 | |
| 31 | if [[ -z $(ps -ef |grep ${service}) ]] |
| 32 | then |
| 33 | print "Hum service down !?! , anyway Service will updating\n" |
| 34 | else |
| 35 | print "Plex is running, service will stop before Update...\n" |
| 36 | fi |
| 37 | # Stop Plex Service |
| 38 | sudo service plexmediaserver stop |
| 39 | # Install latest version |
| 40 | sudo dpkg -i /tmp/$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu" | grep -Po '(?<=fileName=\")(\S+)(?=\")') |
| 41 | |
| 42 | |
| 43 | ps -ef | grep plex | grep -v grep |
| 44 | [ $? -eq "0" ] && echo "Plex is running back :)" || echo "Plex is not running ... ;(" |
| 45 | |
| 46 | # Start Plex Service |
| 47 | echo -e " restart service Plex" |
| 48 | sudo service plexmediaserver start |
| 49 | |
| 50 | # Remove installation package from /tmp folder |
| 51 | rm /tmp/plexmediaserver_* |
| 52 |