Skip to content

Instantly share code, notes, and snippets.

@lesander
Created October 22, 2022 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesander/918c8c2efe7555f9ef586617a1b3827e to your computer and use it in GitHub Desktop.
Save lesander/918c8c2efe7555f9ef586617a1b3827e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Plex update script
# requires jq, curl, wget and sha1sum
# written for debian systemd environments
# CONFIGURATION
url="https://plex.tv/api/downloads/5.json?channel=plexpass"
package="plexmediaserver"
service="$package.service"
build="linux-x86_64"
distro="debian"
tmp_installer_dir="/tmp/path/to/plex/installers"
# 1. Get the latest release information.
json=$(curl -s "$url")
latest_version=$(echo $json | jq -r .computer.Linux.version)
release_date=$(echo $json | jq .computer.Linux.release_date)
release_date=$(date -d @$release_date)
release_notes=$(echo $json | jq -r .computer.Linux.items_added)
release_notes+=$(echo $json | jq -r .computer.Linux.items_fixed)
# 2. Determine the currently installed version
current_version=$(dpkg -s $package | grep '^Version:' | awk -F 'Version: ' '{print $2}')
# 3. Display metadata and ask if we should update.
echo "Latest Plex release"
echo "Released on: $release_date"
echo "Version: $latest_version"
echo "Release notes:"
echo "$release_notes"
echo "----------------------------"
if [[ "$current_version" == "$latest_version" ]]; then
echo "You already have the latest version of Plex installed."
else
echo "You currently have version $current_version"
fi
read -p "Do you want to (re)install the latest Plex release? [y/N]" -n 1 -r
echo " "
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then
exit 1
fi
# 4. Download and verify the installer.
selected_release=$(echo $json | jq '.computer.Linux.releases[] | select(.build == "'$build'" and .distro == "'$distro'")')
installer_url=$(echo $selected_release | jq -r .url)
installer_filename=$(basename $installer_url)
installer_location="$tmp_installer_dir/$installer_filename"
wget -O $installer_location $installer_url
downloaded_release_sha1=$(sha1sum $installer_location | awk -F ' ' '{print $1}')
selected_release_sha1=$(echo $selected_release | jq -r .checksum)
if [[ "$downloaded_release_sha1" == "$selected_release_sha1" ]]; then
echo "Checksum of downloaded installer matches release SHA1"
else
echo "Checksum does not match!"
echo "Release SHA1: $selected_release_sha1"
echo "Downloaded: $downloaded_release_sha1"
exit 0
fi
# 5. Stop the service
echo "Stopping $service service.."
sudo systemctl stop $service
# 6. Install the service and start afterwards.
echo "Installing the latest release.."
sudo dpkg -i $installer_location
echo "Starting $service service.."
sudo systemctl start $service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment