diff --git a/README.md b/README.md index 1559db5..12a6579 100755 --- a/README.md +++ b/README.md @@ -19,6 +19,12 @@ If you'd ever like to change your configuration, just re-run the installer from If you have any trouble with the installer, or would just prefer to set plexupdate up manually, [read the guide](https://github.com/mrworf/plexupdate/wiki/Manually-installing-plexupdate). +## Synology Installation + +Before installing on a Synology NAS, you will need to follow the instructions in the Plex support article [How to add Plex’s package signing public key to Synology NAS Package Center](https://support.plex.tv/articles/205165858-how-to-add-plex-s-package-signing-public-key-to-synology-nas-package-center/). + +Then you can follow the regular installation instructions as normal. + # Advanced options There are a few additional options for the more enterprising user. Setting any of these to `yes` will enable the function. diff --git a/extras/installer.sh b/extras/installer.sh index 5f0967a..538726f 100755 --- a/extras/installer.sh +++ b/extras/installer.sh @@ -4,7 +4,8 @@ ORIGIN_REPO="https://github.com/${GIT_OWNER:-mrworf}/plexupdate" FULL_PATH="/opt/plexupdate" CONFIGFILE="/etc/plexupdate.conf" CONFIGCRON="/etc/plexupdate.cron.conf" -CRONWRAPPER="/etc/cron.daily/plexupdate" +CRONWRAPPER="/etc/cron.d/plexupdate" +CRONWRAPPER_LEGACY="/etc/cron.daily/plexupdate" VERBOSE=yes #to be inherited by get-plex-token, do not save to config # default options @@ -42,6 +43,9 @@ check_distro() { elif hash apt-get 2>/dev/null; then DISTRO="debian" DISTRO_INSTALL="apt-get install" + elif [ -f /etc/synoinfo.conf ]; then + DISTRO="synology" + DISTRO_INSTALL="synopkg install" else DISTRO="unknown" fi @@ -179,9 +183,10 @@ configure_plexupdate() { if yesno "$AUTOINSTALL"; then AUTOINSTALL=yes - + AUTODELETE=yes + [ -z "$DISTRO" ] && check_distro - if [ "$DISTRO" == "redhat" ]; then + if [ "$DISTRO" == "redhat" -o "$DISTRO" == "synology" ]; then AUTOSTART=yes else AUTOSTART= @@ -236,6 +241,11 @@ configure_cron() { return 1 fi + if [ -f "CRONWRAPPER_LEGACY" -a ! -L "CRONWRAPPER_LEGACY" ]; then + echo "It seems like you have a custom cron job for plexupdate. Skipping cron job configuration." + return 1 + fi + [ -f "$CONFIGCRON" ] && source "$CONFIGCRON" echo @@ -274,7 +284,14 @@ configure_cron() { echo echo -n "Installing daily cron job... " - sudo ln -sf "${FULL_PATH}/extras/cronwrapper" "$CRONWRAPPER" + + schedule=$(grep "cron.daily" crontab) + if [ -z "$schedule" ]; then + schedule="0 4 * * * " + else + schedule=${schedule%%root*} + fi + save_cronjob "$schedule" "$CRONWRAPPER" echo "done" elif [ -f "$CRONWRAPPER" -o -f "$CONFIGCRON" ]; then echo @@ -287,6 +304,20 @@ configure_cron() { fi echo done fi + + if [ -f "$CRONWRAPPER_LEGACY" ]; then + sudo rm "$CRONWRAPPER_LEGACY" || echo "Failed to remove old cron configuration, please check '$CRONWRAPPER_LEGACY'" + fi +} + +save_cronjob() { + CONFIGTEMP=$(mktemp /tmp/plexupdate.XXX) + echo "$(grep "MAILTO=" /etc/crontab)" >> $CONFIGTEMP + echo "$(grep "PATH=" /etc/crontab)" >> $CONFIGTEMP + echo "#minute hour mday month wday who command" >> $CONFIGTEMP + echo "${1}root $(which sh) ${FULL_PATH}/extras/cronwrapper" >> $CONFIGTEMP + + save_config_tmp "$CONFIGTEMP" "$2" } save_config() { @@ -297,15 +328,19 @@ save_config() { fi done + save_config_tmp "$CONFIGTEMP" "$2" +} + +save_config_tmp() { echo echo -n "Writing configuration file '$2'... " # most likely writing to /etc, so we need sudo - sudo tee "$2" > /dev/null < "$CONFIGTEMP" + sudo tee "$2" > /dev/null < "$1" sudo chmod 640 "$2" # only root can modify the config, but the user can still read it sudo chown 0:$(id -g) "$2" - rm "$CONFIGTEMP" + rm "$1" echo "done" } diff --git a/plexupdate-core b/plexupdate-core index 4d81751..fd0991c 100755 --- a/plexupdate-core +++ b/plexupdate-core @@ -51,7 +51,7 @@ getPlexToken() { fi done while true; do - read -e -p "PlexPass Password: " -i "$PASS" PASS + read -e -s -p "PlexPass Password: " -i "$PASS" PASS if [ -z "$PASS" ]; then info "Please provide a password" else @@ -226,17 +226,21 @@ isNewerVersion() { } parseVersion() { - if [ "${REDHAT}" = "yes" ]; then + if [ "${DISTRO}" = "redhat" ]; then cut -f2- -d- <<< "$1" | cut -f1-4 -d. + elif [ "${DISTRO}" = "synology" ]; then + cut -f2-3 -d- <<< "$1" else cut -f2 -d_ <<< "$1" fi } getPlexVersion() { - if [ "${REDHAT}" != "yes" ]; then + if [ "${DISTRO}" = "debian" ]; then dpkg-query --showformat='${Version}' --show plexmediaserver 2>/dev/null - elif hash rpm 2>/dev/null; then + elif [ "${DISTRO}" = "synology" ]; then + synopkg version "Plex Media Server" 2>/dev/null + elif [ "${DISTRO}" = "redhat" ]; then local rpmtemp if rpmtemp=$(rpm -q plexmediaserver); then parseVersion "$rpmtemp" diff --git a/plexupdate.sh b/plexupdate.sh index 679ab9c..cbb7050 100755 --- a/plexupdate.sh +++ b/plexupdate.sh @@ -304,15 +304,16 @@ if [ -z "${DISTRO_INSTALL}" ]; then if [ -z "${DISTRO}" ]; then # Detect if we're running on redhat instead of ubuntu if [ -f /etc/redhat-release ]; then - REDHAT=yes DISTRO="redhat" if ! hash dnf 2>/dev/null; then DISTRO_INSTALL="${REDHAT_INSTALL/dnf/yum}" else DISTRO_INSTALL="${REDHAT_INSTALL}" fi + elif [ -f /etc/synoinfo.conf ]; then + DISTRO="synology" + DISTRO_INSTALL="synopkg install" else - REDHAT=no DISTRO="debian" DISTRO_INSTALL="${DEBIAN_INSTALL}" fi @@ -428,7 +429,7 @@ INSTALLED_VERSION="$(getPlexVersion)" || warn "Unable to detect installed versio FILE_VERSION="$(parseVersion "${FILENAME}")" verboseOutput INSTALLED_VERSION FILE_VERSION -if [ "${REDHAT}" = "yes" -a "${AUTOINSTALL}" = "yes" -a "${AUTOSTART}" = "no" ]; then +if [ "${DISTRO}" = "redhat" -a "${AUTOINSTALL}" = "yes" -a "${AUTOSTART}" = "no" ]; then warn "Your distribution may require the use of the AUTOSTART [-s] option for the service to start after the upgrade completes." fi @@ -487,7 +488,7 @@ if [ -n "${PLEXSERVER}" -a "${AUTOINSTALL}" = "yes" ]; then fi if [ "${AUTOINSTALL}" = "yes" ]; then - if ! hash ldconfig 2>/dev/null && [ "${REDHAT}" = "no" ]; then + if ! hash ldconfig 2>/dev/null && [ "${DISTRO}" != "redhat" ]; then export PATH=$PATH:/sbin fi @@ -496,6 +497,9 @@ if [ "${AUTOINSTALL}" = "yes" ]; then if [ ${RET} -ne 0 ]; then # Clarify why this failed, so user won't be left in the dark error "Failed to install update. Command '${DISTRO_INSTALL} "${DOWNLOADDIR}/${FILENAME}"' returned error code ${RET}" + if [ "${DISTRO}" = "synology" -a ${RET} -eq 1 ]; then + error "On Synology devices, you need to add Plex's public key to Package Center. If you have not done so, follow the instructions at https://support.plex.tv/articles/205165858-how-to-add-plex-s-package-signing-public-key-to-synology-nas-package-center/" + fi exit ${RET} fi fi @@ -510,7 +514,7 @@ if [ "${AUTODELETE}" = "yes" ]; then fi if [ "${AUTOSTART}" = "yes" ]; then - if [ "${REDHAT}" = "no" ]; then + if [ "${DISTRO}" != "redhat" -a "${DISTRO}" != "synology" ]; then warn "The AUTOSTART [-s] option may not be needed on your distribution." fi # Check for systemd @@ -520,6 +524,8 @@ if [ "${AUTOSTART}" = "yes" ]; then service plexmediaserver start elif [ -x /etc/init.d/plexmediaserver ]; then /etc/init.d/plexmediaserver start + elif [ "${DISTRO}" = "synology" ]; then + synopkg start "Plex Media Server" else error "AUTOSTART was specified but no startup scripts were found for 'plexmediaserver'." exit 1