Loading

updater-plex.sh

  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. if [[ -z $VersionInstalled ]]; then echo " Plex is not installed - exit "; exit; fi
  20.  
  21. VersionAvailable=$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu" | grep -Po '(?<=(\" version=\"))(\S+)(?=(\"))')
  22. echo -e " Checking $service version ... "
  23. echo -e " Version installed = $VersionInstalled"
  24. echo -e " Version Available = $VersionAvailable"
  25.  
  26. if [ $VersionAvailable = $VersionInstalled ]; then echo "Plex Media Server is already up-to-date (version $VersionInstalled) ... Bye! "; exit; fi
  27.  
  28. echo -e " Download new Version  $VersionAvailable"
  29. # Download latest installation package to /tmp folder
  30. 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/
  31.  
  32. if [[ -z $(ps -ef |grep ${service}) ]]
  33. then
  34.    print "Hum service down !?! , anyway Service will updating\n"
  35. else
  36.    print "Plex is running, service will stop before Update...\n"
  37. fi
  38. # Stop Plex Service
  39. sudo service plexmediaserver stop
  40. # Install latest version
  41. 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+)(?=\")')
  42.  
  43.  
  44. ps -ef | grep plex | grep -v grep
  45. [ $?  -eq "0" ] && echo "Plex is running back :)" || echo "Plex is not running ... ;("
  46.  
  47. # Start Plex Service
  48. echo -e " restart service Plex"
  49. sudo service plexmediaserver start
  50.  
  51. # Remove installation package from /tmp folder
  52. rm /tmp/plexmediaserver_*

Comments