Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
47 changes: 41 additions & 6 deletions extras/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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"
}
Expand Down
12 changes: 8 additions & 4 deletions plexupdate-core
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally kept password echo on since plexupdate is meant to still be accessible to non-technical people, and they often get confused when no output appears while typing. (And bash still doesn't provide a way to replace characters with * or something similar.)

I'm ok with trying it and seeing if we get any issues filed about it, but I also view it as unnecessary in this case, so I'll leave the decision up to you.

if [ -z "$PASS" ]; then
info "Please provide a password"
else
Expand Down Expand Up @@ -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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, functions like these should generally start with the "default" option (Ubuntu/Debian) and then go on to the other cases. It's just a bit confusingly written right now because of how the REDHAT variable is used. I'd suggest swapping the two first cases and adding a comment (which I really should have done when I wrote the function 🤦‍♂ ), about what the "${REDHAT}" != "yes" does.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way GitHub is rendering this is a bit confusing. The comment is about the getPlexVersion function, not isNewerVersion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if I just switch the cases like so

	if [ "${REDHAT}" != "yes" ]; then
		dpkg-query --showformat='${Version}' --show plexmediaserver 2>/dev/null
	elif [ "${DISTRO}" = "synology" ]; then
		synopkg version "Plex Media Server" 2>/dev/null

I don't think the switch ever reaches the synology case because "${REDHAT}" != "yes" is true for synology devices too.

I'm not sure how best to change it.

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"
Expand Down
16 changes: 11 additions & 5 deletions plexupdate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,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
Expand Down Expand Up @@ -424,7 +425,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

Expand Down Expand Up @@ -483,7 +484,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

Expand All @@ -492,6 +493,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
Expand All @@ -506,7 +510,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
Expand All @@ -516,6 +520,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
Expand Down