Last active
March 2, 2022 07:56
-
-
Save sampi/ac96e9b964a9a73345821ea4407bf1c1 to your computer and use it in GitHub Desktop.
Plex Media Player on Raspberry Pi, Nightlies Auto-Updater script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| PMP_HOST='192.168.86.117'; | |
| PMP_USER='root'; | |
| PMP_PASS='plex'; | |
| LATEST_URL='https://nightlies.plex.tv/public-test/plexmediaplayer/embedded-testing/latest-full/'; | |
| PMP_UPDATE_FOLDER='/storage/.update/' | |
| CURRENT_FILE='current_pmp.txt'; | |
| HASH_PATTERN='([0-9a-f]{8})'; | |
| cd "$(dirname "$0")"; | |
| touch "${CURRENT_FILE}"; | |
| LOADED_TAR=$(cat "${CURRENT_FILE}"); | |
| LOADED_HASH=$(cat "${CURRENT_FILE}" | grep -Eoi $HASH_PATTERN); | |
| echo "Currently loaded tar: ${LOADED_TAR} (${LOADED_HASH})"; | |
| echo "Checking latest tar"; | |
| LATEST_TAR=$(curl --silent "${LATEST_URL}" | grep -Eoi '<a [^>]+>' | grep -Eo 'href="[^\"]+"' | grep -Eo '[^/"]+arm.tar'); | |
| LATEST_HASH=$(echo $LATEST_TAR | grep -Eoi $HASH_PATTERN); | |
| echo "Latest available tar: ${LATEST_TAR} (${LATEST_HASH})"; | |
| if [ "$LOADED_HASH" != "$LATEST_HASH" ]; then | |
| echo "Found new version!"; | |
| wget "${LATEST_URL}${LATEST_TAR}"; | |
| ssh-keygen -F "${PMP_HOST}"; | |
| ZERO_IF_HOST_IS_KNOWN=$?; | |
| if [ $ZERO_IF_HOST_IS_KNOWN != 0 ]; then | |
| echo "Adding '${PMP_HOST}' to '~/.ssh/known_hosts'"; | |
| USER_HOME=$(eval echo ~$USER) | |
| ssh-keyscan -H "${PMP_HOST}" >> "${USER_HOME}/.ssh/known_hosts"; | |
| rc=$?; if [ $rc != 0 ]; then exit $rc; fi | |
| fi | |
| echo "Deleting any update files from Raspberry Pi Plex Media Player"; | |
| sshpass -p "${PMP_PASS}" ssh "${PMP_USER}@${PMP_HOST}" "rm -f ${PMP_UPDATE_FOLDER}*.tar"; | |
| rc=$?; if [ $rc != 0 ]; then exit $rc; fi | |
| echo "Uploading to Raspberry Pi Plex Media Player (this might take a while...)"; | |
| sshpass -p "${PMP_PASS}" scp "${LATEST_TAR}" "${PMP_USER}@${PMP_HOST}:${PMP_UPDATE_FOLDER}"; | |
| rc=$?; if [ $rc != 0 ]; then exit $rc; fi | |
| echo "Cleaning up downloads"; | |
| rm -f ./*.tar; | |
| echo "Updating current hash." | |
| echo "${LATEST_TAR}" > "${CURRENT_FILE}"; | |
| echo "Update successful, restarting Raspberry Pi to apply the update."; | |
| sshpass -p "${PMP_PASS}" ssh "${PMP_USER}@${PMP_HOST}" "{ sleep 1; reboot; } > /dev/null &"; | |
| rc=$?; if [ $rc != 0 ]; then exit $rc; fi | |
| else | |
| echo "No new version found."; | |
| exit 1; | |
| fi | |
| exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would this work on NUC intel with PMP generic builds.