mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-07-06 05:01:15 -07:00
Switch to using only tokens for plexupdate.sh (#169)
* Extract token fetching to extras/get-plex-token * Have installer store TOKEN instead of EMAIL/PASS * Provide easy way to pass git owner/branch while testing * Use path when sourcing get-web-token * Don't force interactive mode for EMAIL/PASS if they're already stored * Re-enable getting plex token from server * Try to read server token as sudo if possible * Specify branch to clone in installer.sh * Better checking of where token came from * Make VERBOSE useful again * Fix getPlexServerToken if installer.sh is being run from wget * Extract functions into plexupdate-core * Use plexupdate-core in installer * Clean up usage and add --help * Deprecate FORCEALL * Make CHECKUPDATE check all program files * Verify plex.tv is providing a checksum before downloading * Add some more logging for release handling * Use info/warn/error in plexupdate-core * Remove outdated instructions from plexupdate.sh * Only store tokens if PMS token is unavailable * Warn users if fetching Plex token fails in installer * Use local vars in functions and fix getRemoteSHA * Update README * Deprecate EMAIL/PASS and add token command-line option * Quote option names * Update FAQs * Add link to FAQ in deprecation notice * Remove trailing whitespace * Make cron return 0 when plexupdate returns 10
This commit is contained in:
parent
acb8cc2fb8
commit
37f75bcd32
5 changed files with 351 additions and 416 deletions
169
README.md
169
README.md
|
@ -3,11 +3,7 @@
|
||||||
|
|
||||||
Plex Update is a bash script which helps you keep Plex Media Server up to date on Linux.
|
Plex Update is a bash script which helps you keep Plex Media Server up to date on Linux.
|
||||||
|
|
||||||
plexupdate will automatically download the latest version of Plex Media Server for Linux and, optionally, also install it for you.
|
You can schedule updates to run daily and install Plex Pass beta releases if you have a Plex Pass membership.
|
||||||
|
|
||||||
### What happened to `.plexupdate` ?
|
|
||||||
|
|
||||||
It has gone away to keep things simpler and more secure. You can either provide the config you want using the `--config` parameter or place it in `/etc/plexupdate.conf`.
|
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
|
@ -19,131 +15,50 @@ bash -c "$(wget -qO - https://raw.githubusercontent.com/mrworf/plexupdate/master
|
||||||
|
|
||||||
will automatically install the tool as well as any dependencies. This has been tested on Ubuntu, Fedora and CentOS but should, for the most part, work on any modern Linux distribution.
|
will automatically install the tool as well as any dependencies. This has been tested on Ubuntu, Fedora and CentOS but should, for the most part, work on any modern Linux distribution.
|
||||||
|
|
||||||
If you'd ever like to change your configuration, you can just re-run this from the extras folder inside your plexupdate directory. (`/opt/plexupdate/extras/installer.sh` by default)
|
If you'd ever like to change your configuration, just re-run the installer from the extras folder inside your plexupdate directory. (`/opt/plexupdate/extras/installer.sh` by default)
|
||||||
|
|
||||||
If you have any trouble with the installer, or would just prefer to set plexupdate up manually, read on.
|
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).
|
||||||
|
|
||||||
## 1. Getting the code
|
# Advanced options
|
||||||
|
|
||||||
####Using git to clone (recommended)
|
There are a few additional options for the more enterprising user. Setting any of these to `yes` will enable the function.
|
||||||
```
|
|
||||||
git clone https://github.com/mrworf/plexupdate.git
|
|
||||||
```
|
|
||||||
Note that git is required (`sudo apt-get install git`)
|
|
||||||
|
|
||||||
This is the recommended way to install plexupdate. Using git allows you to know when a new version is available as well allowing plexupdate to keep itself up to date (with the AUTOUPDATE option).
|
- `CHECKUPDATE`
|
||||||
|
If you didn't install using `git clone` or by running the installer, you can use this option to notify you when there are updates to plexupdate. If you used git or the installer, see `AUTOUPDATE` instead.
|
||||||
####Using wget and unzip
|
- `PLEXSERVER`
|
||||||
|
If set, and combined with `AUTOINSTALL`, the script will automatically check if the server is in use and defer the update. Great for crontab users. `PLEXSERVER` should be set to the IP/DNS of your Plex Media Server, which typically is 127.0.0.1
|
||||||
Download it as a [zip file](https://github.com/mrworf/plexupdate/archive/master.zip) and unzip it on your server.
|
- `PLEXPORT`
|
||||||
```
|
Sets the port to use along with `PLEXSERVER`
|
||||||
wget https://github.com/mrworf/plexupdate/archive/master.zip && unzip master.zip && mv plexupdate-master plexupdate && rm master.zip
|
- `AUTOUPDATE`
|
||||||
```
|
Makes plexupdate.sh automatically update itself using git. This only works if you installed using `git clone` or by using the installer.
|
||||||
Note that unzip is required (`sudo apt-get install unzip`).
|
- `AUTOINSTALL`
|
||||||
|
Automatically installs the newly downloaded version. Currently works for Debian based systems as well as rpm based distros. Requires root permissions.
|
||||||
## 2. Setting it up
|
- `AUTODELETE`
|
||||||
|
Delete the downloaded package after installation is complete to conserve disk space.
|
||||||
In order to use `plexupdate.sh`, it's recommended you create a configuration file.
|
- `PUBLIC`
|
||||||
|
The default behavior of plexupdate.sh is to download the PlexPass edition of Plex Media Server. Setting this option to `yes` will make it download the public version instead.
|
||||||
```
|
- `FORCE`
|
||||||
sudo nano -w /etc/plexupdate.conf
|
|
||||||
```
|
|
||||||
|
|
||||||
In the newly opened editor, insert the following (and make *sure* to change email and password)
|
|
||||||
|
|
||||||
```
|
|
||||||
EMAIL='john.doe@void.com'
|
|
||||||
PASS='verySecretPassword'
|
|
||||||
DOWNLOADDIR='/tmp/'
|
|
||||||
```
|
|
||||||
|
|
||||||
This will make `plexupdate.sh` login and download the latest version and save it to /tmp/ folder.
|
|
||||||
|
|
||||||
If you don't have PlexPass, you can still use `plexupdate.sh`, just set `PUBLIC=yes` instead. The section above becomes
|
|
||||||
|
|
||||||
```
|
|
||||||
PUBLIC=yes
|
|
||||||
DOWNLOADDIR='/tmp/'
|
|
||||||
```
|
|
||||||
|
|
||||||
## 3. Cronjob
|
|
||||||
|
|
||||||
You might be more interested in running this on a regular basis. To accomplish this, we need to do the following. Locate the `extras` folder which was included with plexupdate. In this folder you'll find `cronwrapper`. You need to "symlink" this into `/etc/cron.daily/`. Symlink means we tell the system that there should be reference/link to the file included in plexupdate. By not copying, we will automatically get updates to the `cronwrapper` when we update plexupdate.
|
|
||||||
|
|
||||||
When doing the symlink, it's important to provide the complete path to the file in question, so you will need to edit the path to it in the following snippet. Also, we need to run as root, since only root is allowed to edit files under `/etc`.
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo ln -s /home/john/plexupdate/extras/cronwrapper /etc/cron.daily/plexupdate
|
|
||||||
```
|
|
||||||
|
|
||||||
We also need to tell cronwrapper where to find plexupdate, again, this needs to be done as root for the same reasons as above.
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo nano -w /etc/plexupdate.cron.conf
|
|
||||||
```
|
|
||||||
|
|
||||||
In the new file, we simply point out the location of `plexupdate.sh` and `plexupdate.conf`
|
|
||||||
|
|
||||||
```
|
|
||||||
SCRIPT=/home/john/plexupdate/plexupdate.sh
|
|
||||||
CONF=/home/john/plexupdate.conf
|
|
||||||
```
|
|
||||||
|
|
||||||
If you've installed it somewhere else and/or the path to the config is somewhere else, please *make sure* to write the correct paths.
|
|
||||||
|
|
||||||
Almost done. Final step is to make `plexupdate.sh` a bit smarter and have it install the newly downloaded version, so open the `plexupdate.conf` file you created previously and add the following:
|
|
||||||
|
|
||||||
```
|
|
||||||
AUTOINSTALL=yes
|
|
||||||
AUTODELETE=yes
|
|
||||||
```
|
|
||||||
|
|
||||||
This tells `plexupdate.sh` to install the file once downloaded and delete it when done, keeping your server nice and clean.
|
|
||||||
|
|
||||||
## 4. Advanced options
|
|
||||||
|
|
||||||
There are also a few additional options for the more enterprising user. Setting any of these to `yes` will enable the function.
|
|
||||||
|
|
||||||
- CHECKUPDATE
|
|
||||||
If set (and it is by default), it will compare your local copy with the one stored on github. If there is any difference, it will let you know. This is handy if you're not using `git clone` but want to be alerted to new versions.
|
|
||||||
- PLEXSERVER
|
|
||||||
If set, and combined with AUTOINSTALL, the script will automatically check if the server is in-use and defer the update. Great for crontab users. PLEXSERVER should be set to the IP/DNS of your Plex Media Server, which typically is 127.0.0.1
|
|
||||||
- PLEXPORT
|
|
||||||
Sets the port to use along with PLEXSERVER
|
|
||||||
- AUTOUPDATE
|
|
||||||
Makes plexupdate.sh automatically update itself using git. Note! This will fail if git isn't available on the command line.
|
|
||||||
- AUTOINSTALL
|
|
||||||
Automatically installs the newly downloaded version. Currently works for Debian based systems as well as rpm based distros. Will fail miserably if you're not root.
|
|
||||||
- AUTODELETE
|
|
||||||
Once successfully downloaded and installed, it will delete the package (want not, waste not? ;-))
|
|
||||||
- PUBLIC
|
|
||||||
The default behavior of plexupdate.sh is to download the PlexPass edition of Plex Media Server. Setting this option to `yes` will make it download the public version instead. If this is yes, then `EMAIL` and `PASS` is no longer needed.
|
|
||||||
- FORCE
|
|
||||||
Normally plexupdate.sh will avoid downloading a file it already has or if it's the same as the installed version. Using this option will force it to download again UNLESS the file already downloaded has the correct checksum. If you have AUTOINSTALL set, plexupdate.sh will then reinstall it.
|
Normally plexupdate.sh will avoid downloading a file it already has or if it's the same as the installed version. Using this option will force it to download again UNLESS the file already downloaded has the correct checksum. If you have AUTOINSTALL set, plexupdate.sh will then reinstall it.
|
||||||
- FORCEALL
|
- `PRINT_URL`
|
||||||
Using this option will force plexupdate.sh to override the checksum check and will download the file again, and if you have AUTOINSTALL set, will reinstall it.
|
|
||||||
- PRINT_URL
|
|
||||||
Authenticate, fetch the download URL, print it, and then exit.
|
Authenticate, fetch the download URL, print it, and then exit.
|
||||||
- DISTRO_INSTALL
|
- `DISTRO_INSTALL`
|
||||||
The command used to install packages, only change if you need special options. Natively supports Debian and Redhat, so you don't need to set this for these systems.
|
The command used to install packages, only change if you need special options. Natively supports Debian and Redhat, so you don't need to set this for these systems.
|
||||||
NOTE! If you define this, you MUST define DISTRO and BUILD
|
NOTE! If you define this, you MUST define `DISTRO` and `BUILD`
|
||||||
- DISTRO and BUILD
|
- `DISTRO` and `BUILD`
|
||||||
Override which version to download, use -l option to see what you can select.
|
Override which version to download, use -l option to see what you can select.
|
||||||
|
- `TOKEN`
|
||||||
|
If you want to install Plex Pass releases, plexupdate will try to get your account token directly from your Plex Media Server. If you want to use a different token to authenticate, you can enter it here instead. Please read [Authenticating with Plex Pass](https://github.com/mrworf/plexupdate/wiki/Authenticating-with-Plex-Pass) on the wiki for more details.
|
||||||
|
|
||||||
Most of these options can be specified on the command-line as well, this is just a more convenient way of doing it if you're scripting it. Which brings us to...
|
Most of these options can be specified on the command-line as well, this is just a more convenient way of doing it if you're scripting it. Which brings us to...
|
||||||
|
|
||||||
### Command Line Options
|
## Command Line Options
|
||||||
|
|
||||||
Plexupdate comes with many command line options. For the most up-to-date list, I'd recommend you run plexupdate.sh with -h
|
Plexupdate comes with many command line options. For the most up-to-date list, run plexupdate.sh with -h
|
||||||
|
|
||||||
But here are some of the more useful ones:
|
Here are some of the more useful ones:
|
||||||
|
|
||||||
- `--config <path/to/config/file>`
|
- `--config <path/to/config/file>`
|
||||||
Defines the location the script should look for the config file.
|
Defines the location the script should look for the config file.
|
||||||
- `--email <Plex.tv email>`
|
|
||||||
Email to sign in to Plex.tv
|
|
||||||
- `--pass <Plex.tv password>`
|
|
||||||
Password to sign in to Plex.tv
|
|
||||||
- `--dldir <path/to/where/you/want/files/downloaded/to>`
|
- `--dldir <path/to/where/you/want/files/downloaded/to>`
|
||||||
This is the folder that the files will be downloaded to.
|
This is the folder that the files will be downloaded to.
|
||||||
- `--server <Plex server address>`
|
- `--server <Plex server address>`
|
||||||
|
@ -151,32 +66,16 @@ But here are some of the more useful ones:
|
||||||
- `--port <Plex server port>`
|
- `--port <Plex server port>`
|
||||||
This is the port that Plex Media Server uses.
|
This is the port that Plex Media Server uses.
|
||||||
|
|
||||||
# Trivia
|
|
||||||
|
|
||||||
- "kaka" is Swedish for "cookie"
|
|
||||||
|
|
||||||
# FAQ
|
# FAQ
|
||||||
|
|
||||||
## Where is `.plexupdate`
|
## Do I have to use the `extras/installer.sh`?
|
||||||
|
|
||||||
See explanation in the top of this document.
|
Of course not, anything you find under `extras/` is optional and only provided as an easier way to get `plexupdate.sh` up and running quickly. Read the guide for [installing plexupdate manually](https://github.com/mrworf/plexupdate/wiki/Manually-installing-plexupdate).
|
||||||
|
|
||||||
## Do I have to use the `extras/installer.sh` ?
|
## Why am I getting a warning about email and password being deprecated?
|
||||||
|
|
||||||
Of course not, anything you find under `extras/` is optional and only provided as a easier way to get `plexupdate.sh` up and running quickly.
|
Since just storing your password in plexupdate.conf isn't secure, plexupdate will now use a "token" instead. To make this warning go away just re-run the installer (`extras/installer.sh`) or manually remove `EMAIL` and `PASS` from your plexupdate.conf. For more details, see [this wiki article](https://github.com/mrworf/plexupdate/wiki/Authenticating-with-Plex-Pass).
|
||||||
|
|
||||||
## What email and password are you talking about
|
# Need more information?
|
||||||
|
|
||||||
The email and password for http://plex.tv
|
|
||||||
|
|
||||||
## My password is rejected even though correct
|
|
||||||
|
|
||||||
If you use certain characters (such as `$`) in your password, bash will interpret that as a reference to a variable. To resolve this, enclose your password within single quotes (`'`) instead of the normal quotes (`"`).
|
|
||||||
|
|
||||||
i.e. `PASS="MyP4$$w0rD"` will not work, but changing to it to `PASS='MyP4$$w0rD'` will
|
|
||||||
|
|
||||||
If it's still not working, run `plexupdate.sh` with `-v` which prints out the email and password used to login which might help you understand what the problem is.
|
|
||||||
|
|
||||||
# Not finding what you're looking for?
|
|
||||||
|
|
||||||
See https://github.com/mrworf/plexupdate/wiki for more information
|
See https://github.com/mrworf/plexupdate/wiki for more information
|
||||||
|
|
|
@ -58,6 +58,11 @@ fi
|
||||||
if [ $RET -ne 0 ] ; then
|
if [ $RET -ne 0 ] ; then
|
||||||
# Make sure user gets an email about this (when not success or if user has specified when)
|
# Make sure user gets an email about this (when not success or if user has specified when)
|
||||||
cat ${LOGFILE} >&2
|
cat ${LOGFILE} >&2
|
||||||
|
|
||||||
|
# Output will produce a cron email, so we can reset the exit status
|
||||||
|
if [ $RET -eq 10 ]; then
|
||||||
|
RET=0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm "${LOGFILE}" 2>/dev/null
|
rm "${LOGFILE}" 2>/dev/null
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
ORIGIN_REPO="https://github.com/mrworf/plexupdate"
|
ORIGIN_REPO="https://github.com/${GIT_OWNER:-mrworf}/plexupdate"
|
||||||
FULL_PATH="/opt/plexupdate"
|
FULL_PATH="/opt/plexupdate"
|
||||||
CONFIGFILE="/etc/plexupdate.conf"
|
CONFIGFILE="/etc/plexupdate.conf"
|
||||||
CONFIGCRON="/etc/plexupdate.cron.conf"
|
CONFIGCRON="/etc/plexupdate.cron.conf"
|
||||||
CRONWRAPPER="/etc/cron.daily/plexupdate"
|
CRONWRAPPER="/etc/cron.daily/plexupdate"
|
||||||
|
VERBOSE=yes #to be inherited by get-plex-token, do not save to config
|
||||||
|
|
||||||
# default options
|
# default options
|
||||||
AUTOINSTALL=yes
|
AUTOINSTALL=yes
|
||||||
|
@ -12,7 +13,7 @@ AUTOUPDATE=yes
|
||||||
PUBLIC=
|
PUBLIC=
|
||||||
|
|
||||||
# variables to save in config
|
# variables to save in config
|
||||||
CONFIGVARS="AUTOINSTALL AUTODELETE DOWNLOADDIR EMAIL PASS FORCE FORCEALL PUBLIC AUTOSTART AUTOUPDATE PLEXSERVER PLEXPORT CHECKUPDATE NOTIFY"
|
CONFIGVARS="AUTOINSTALL AUTODELETE DOWNLOADDIR TOKEN FORCE FORCEALL PUBLIC AUTOSTART AUTOUPDATE PLEXSERVER PLEXPORT CHECKUPDATE NOTIFY"
|
||||||
CRONVARS="CONF SCRIPT LOGGING"
|
CRONVARS="CONF SCRIPT LOGGING"
|
||||||
|
|
||||||
install() {
|
install() {
|
||||||
|
@ -136,7 +137,7 @@ install_plexupdate() {
|
||||||
cd - &> /dev/null
|
cd - &> /dev/null
|
||||||
else
|
else
|
||||||
echo -n "Installing plexupdate into '$FULL_PATH'... "
|
echo -n "Installing plexupdate into '$FULL_PATH'... "
|
||||||
git clone "$ORIGIN_REPO" "$FULL_PATH" &> /dev/null || abort "install failed, cannot continue"
|
git clone --branch "${BRANCHNAME:-master}" "$ORIGIN_REPO" "$FULL_PATH" &> /dev/null || abort "install failed, cannot continue"
|
||||||
echo "done"
|
echo "done"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -146,33 +147,28 @@ configure_plexupdate() {
|
||||||
[ -f "$CONFIGFILE" ] && source "$CONFIGFILE"
|
[ -f "$CONFIGFILE" ] && source "$CONFIGFILE"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo -n "Do you want to install the latest PlexPass releases? (requires PlexPass username and password) "
|
echo -n "Do you want to install the latest PlexPass releases? (requires PlexPass account) "
|
||||||
# The answer to this question and the value of PUBLIC are basically inverted
|
# The answer to this question and the value of PUBLIC are basically inverted
|
||||||
if [ "$PUBLIC" == "yes" ]; then
|
if [ "$PUBLIC" == "yes" ]; then
|
||||||
default=N
|
default=N
|
||||||
fi
|
fi
|
||||||
if yesno $default; then
|
if yesno $default; then
|
||||||
PUBLIC=no
|
PUBLIC=no
|
||||||
while true; do
|
# If they already have a VALID token, leave it alone
|
||||||
read -e -p "PlexPass Email Address: " -i "$EMAIL" EMAIL
|
if [ -z "$TOKEN" ] || ! verifyToken; then
|
||||||
if [ -z "${EMAIL}" ] || [[ "$EMAIL" == *"@"* ]] && [[ "$EMAIL" != *"@"*"."* ]]; then
|
if getPlexServerToken; then
|
||||||
echo "Please provide a valid email address"
|
# Only store the token if it's not in PMS
|
||||||
else
|
TOKEN=
|
||||||
break
|
elif ! getPlexToken; then
|
||||||
|
error "Unable to get Plex token, falling back to pulic release"
|
||||||
|
PUBLIC=yes
|
||||||
fi
|
fi
|
||||||
done
|
fi
|
||||||
while true; do
|
|
||||||
read -e -p "PlexPass Password: " -i "$PASS" PASS
|
|
||||||
if [ -z "$PASS" ]; then
|
|
||||||
echo "Please provide a password"
|
|
||||||
else
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
else
|
||||||
# don't forget to erase old settings if they changed their answer
|
# don't forget to erase old settings if they changed their answer
|
||||||
EMAIL=
|
EMAIL=
|
||||||
PASS=
|
PASS=
|
||||||
|
TOKEN=
|
||||||
PUBLIC=yes
|
PUBLIC=yes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -345,7 +341,7 @@ else
|
||||||
install_plexupdate
|
install_plexupdate
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
source "${FULL_PATH}/plexupdate-core"
|
||||||
|
|
||||||
configure_plexupdate
|
configure_plexupdate
|
||||||
configure_cron
|
configure_cron
|
||||||
|
@ -357,7 +353,7 @@ if yesno; then
|
||||||
PROGRESS_OPT="-P"
|
PROGRESS_OPT="-P"
|
||||||
fi
|
fi
|
||||||
if [ "$AUTOINSTALL" == "yes" ]; then
|
if [ "$AUTOINSTALL" == "yes" ]; then
|
||||||
sudo "$FULL_PATH/plexupdate.sh" $PROGRESS_OPT --config "$CONFIGFILE"
|
sudo -E "$FULL_PATH/plexupdate.sh" $PROGRESS_OPT --config "$CONFIGFILE"
|
||||||
else
|
else
|
||||||
"$FULL_PATH/plexupdate.sh" $PROGRESS_OPT --config "$CONFIGFILE"
|
"$FULL_PATH/plexupdate.sh" $PROGRESS_OPT --config "$CONFIGFILE"
|
||||||
fi
|
fi
|
||||||
|
|
228
plexupdate-core
Executable file
228
plexupdate-core
Executable file
|
@ -0,0 +1,228 @@
|
||||||
|
#!/bin/bash
|
||||||
|
######## INDEX ########
|
||||||
|
# GPT -> getPlexToken
|
||||||
|
# GPS -> getPlexServerToken
|
||||||
|
# GPW -> getPlexWebToken
|
||||||
|
# HELPERS -> keypair, rawurlencode, trimQuotes
|
||||||
|
# RNNG -> running
|
||||||
|
# SHARED -> warn, info, warn
|
||||||
|
|
||||||
|
######## CONSTANTS ########
|
||||||
|
# Current pages we need - Do not change unless Plex.tv changes again
|
||||||
|
URL_LOGIN='https://plex.tv/users/sign_in.json'
|
||||||
|
URL_DOWNLOAD='https://plex.tv/api/downloads/1.json?channel=plexpass'
|
||||||
|
URL_DOWNLOAD_PUBLIC='https://plex.tv/api/downloads/1.json'
|
||||||
|
|
||||||
|
# Default options for package managers, override if needed
|
||||||
|
REDHAT_INSTALL="dnf -y install"
|
||||||
|
DEBIAN_INSTALL="dpkg -i"
|
||||||
|
DISTRO_INSTALL=""
|
||||||
|
|
||||||
|
#URL for new version check
|
||||||
|
UPSTREAM_GIT_URL="https://raw.githubusercontent.com/${GIT_OWNER:-mrworf}/plexupdate/${BRANCHNAME:-master}"
|
||||||
|
|
||||||
|
#Files "owned" by plexupdate, for autoupdate
|
||||||
|
PLEXUPDATE_FILES="plexupdate.sh plexupdate-core extras/installer.sh extras/cronwrapper"
|
||||||
|
|
||||||
|
|
||||||
|
######## FUNCTIONS ########
|
||||||
|
#### Token Management #####
|
||||||
|
|
||||||
|
# GPT
|
||||||
|
getPlexToken() {
|
||||||
|
if [ -n "$TOKEN" ]; then
|
||||||
|
[ "$VERBOSE" = "yes" ] && info "Fetching token from config"
|
||||||
|
elif getPlexServerToken; then
|
||||||
|
[ "$VERBOSE" = "yes" ] && info "Fetching token from Plex server"
|
||||||
|
elif [ -z "$TOKEN" -a -n "$EMAIL" -a -n "$PASS" ]; then
|
||||||
|
warn "Storing your email and password has been deprecated. Please re-run extras/installer.sh or see https://github.com/mrworf/plexupdate#faq"
|
||||||
|
getPlexWebToken
|
||||||
|
# Check if we're connected to a terminal
|
||||||
|
elif [ -z "$TOKEN" -a -t 0 ]; then
|
||||||
|
info "To continue, you will need to provide your Plex account credentials."
|
||||||
|
info "Your email and password will only be used to retrieve a 'token' and will not be saved anywhere."
|
||||||
|
echo
|
||||||
|
while true; do
|
||||||
|
read -e -p "PlexPass Email Address: " -i "$EMAIL" EMAIL
|
||||||
|
if [ -z "${EMAIL}" ] || [[ "$EMAIL" == *"@"* ]] && [[ "$EMAIL" != *"@"*"."* ]]; then
|
||||||
|
info "Please provide a valid email address"
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
while true; do
|
||||||
|
read -e -p "PlexPass Password: " -i "$PASS" PASS
|
||||||
|
if [ -z "$PASS" ]; then
|
||||||
|
info "Please provide a password"
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
getPlexWebToken
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -n "$TOKEN" ] # simulate exit status
|
||||||
|
}
|
||||||
|
|
||||||
|
# GPS
|
||||||
|
getPlexServerToken() {
|
||||||
|
if [ -f /etc/default/plexmediaserver ]; then
|
||||||
|
source /etc/default/plexmediaserver
|
||||||
|
fi
|
||||||
|
|
||||||
|
# List possible locations to find Plex Server preference file
|
||||||
|
local VALIDPATHS=("${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" "/var/lib/plexmediaserver/Library/Application Support/" "${HOME}/Library/Application Support/")
|
||||||
|
local PREFFILE="/Plex Media Server/Preferences.xml"
|
||||||
|
|
||||||
|
for I in "${VALIDPATHS[@]}" ; do
|
||||||
|
if [ ! -z "${I}" -a -f "${I}${PREFFILE}" ]; then
|
||||||
|
# When running installer.sh directly from wget, $0 will return bash
|
||||||
|
if [ "$(basename $0)" = "installer.sh" -o "$(basename $0)" = "bash" ]; then
|
||||||
|
TOKEN=$(sudo sed -n 's/.*PlexOnlineToken="\([[:alnum:]]*\).*".*/\1/p' "${I}${PREFFILE}" 2>/dev/null)
|
||||||
|
else
|
||||||
|
TOKEN=$(sed -n 's/.*PlexOnlineToken="\([[:alnum:]]*\).*".*/\1/p' "${I}${PREFFILE}" 2>/dev/null)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -n "$TOKEN" ] # simulate exit status
|
||||||
|
}
|
||||||
|
|
||||||
|
# GPW
|
||||||
|
getPlexWebToken() {
|
||||||
|
local FILE_POSTDATA=$(mktemp /tmp/plexupdate.postdata.XXXX)
|
||||||
|
local FILE_RAW=$(mktemp /tmp/plexupdate.raw.XXXX)
|
||||||
|
local FILE_FAILCAUSE=$(mktemp /tmp/plexupdate.failcause.XXXX)
|
||||||
|
|
||||||
|
# Fields we need to submit for login to work
|
||||||
|
#
|
||||||
|
# Field Value
|
||||||
|
# utf8 ✓
|
||||||
|
# authenticity_token <Need to be obtained from web page>
|
||||||
|
# user[login] $EMAIL
|
||||||
|
# user[password] $PASS
|
||||||
|
# user[remember_me] 0
|
||||||
|
# commit Sign in
|
||||||
|
|
||||||
|
# Build post data
|
||||||
|
echo -ne >"${FILE_POSTDATA}" "$(keypair "user[login]" "${EMAIL}" )"
|
||||||
|
echo -ne >>"${FILE_POSTDATA}" "&$(keypair "user[password]" "${PASS}" )"
|
||||||
|
echo -ne >>"${FILE_POSTDATA}" "&$(keypair "user[remember_me]" "0" )"
|
||||||
|
|
||||||
|
# Authenticate (using Plex Single Sign On)
|
||||||
|
wget --header "X-Plex-Client-Identifier: 4a745ae7-1839-e44e-1e42-aebfa578c865" --header "X-Plex-Product: Plex SSO" "${URL_LOGIN}" --post-file="${FILE_POSTDATA}" -q -S -O "${FILE_FAILCAUSE}" 2>"${FILE_RAW}"
|
||||||
|
|
||||||
|
# Provide some details to the end user
|
||||||
|
local RESULTCODE=$(head -n1 "${FILE_RAW}" | grep -oe '[1-5][0-9][0-9]')
|
||||||
|
if [ $RESULTCODE -eq 401 ]; then
|
||||||
|
error "Username and/or password incorrect"
|
||||||
|
elif [ $RESULTCODE -ne 201 ]; then
|
||||||
|
error "Failed to log in, debug information:"
|
||||||
|
cat "${FILE_RAW}" >&2
|
||||||
|
else
|
||||||
|
TOKEN=$(<"${FILE_FAILCAUSE}" grep -ioe '"authToken":"[^"]*' | cut -c 14-)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up temp files since they may contain sensitive information
|
||||||
|
rm "${FILE_FAILCAUSE}" "${FILE_POSTDATA}" "${FILE_RAW}"
|
||||||
|
|
||||||
|
[ -n "$TOKEN" ] # simulate exit status
|
||||||
|
}
|
||||||
|
|
||||||
|
# HELPERS
|
||||||
|
keypair() {
|
||||||
|
local key="$( rawurlencode "$1" )"
|
||||||
|
local val="$( rawurlencode "$2" )"
|
||||||
|
|
||||||
|
echo "${key}=${val}"
|
||||||
|
}
|
||||||
|
|
||||||
|
rawurlencode() {
|
||||||
|
local string="${1}"
|
||||||
|
local strlen=${#string}
|
||||||
|
local encoded=""
|
||||||
|
|
||||||
|
for (( pos=0 ; pos<strlen ; pos++ )); do
|
||||||
|
c=${string:$pos:1}
|
||||||
|
case "$c" in
|
||||||
|
[-_.~a-zA-Z0-9] ) o="${c}" ;;
|
||||||
|
* ) printf -v o '%%%02x' "'$c"
|
||||||
|
esac
|
||||||
|
encoded+="${o}"
|
||||||
|
done
|
||||||
|
echo "${encoded}"
|
||||||
|
}
|
||||||
|
|
||||||
|
trimQuotes() {
|
||||||
|
local __buffer=$1
|
||||||
|
|
||||||
|
# Remove leading single quote
|
||||||
|
__buffer=${__buffer#\'}
|
||||||
|
# Remove ending single quote
|
||||||
|
__buffer=${__buffer%\'}
|
||||||
|
|
||||||
|
echo $__buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
getRemoteSHA() {
|
||||||
|
# these two lines can't be combined. `local RESULT=` will gobble up the return
|
||||||
|
local RESULT
|
||||||
|
RESULT=$(wget -q "$1" -O - 2>/dev/null) || return 1
|
||||||
|
sha1sum <<< "$RESULT" | cut -f1 -d" "
|
||||||
|
}
|
||||||
|
|
||||||
|
getLocalSHA() {
|
||||||
|
[ -f "$1" ] || return 1
|
||||||
|
sha1sum "$1" | cut -f1 -d" "
|
||||||
|
}
|
||||||
|
|
||||||
|
# RNNG
|
||||||
|
running() {
|
||||||
|
local DATA="$(wget --no-check-certificate -q -O - https://$1:$3/status/sessions?X-Plex-Token=$2)"
|
||||||
|
local RET=$?
|
||||||
|
if [ ${RET} -eq 0 ]; then
|
||||||
|
if [ -z "${DATA}" ]; then
|
||||||
|
# Odd, but usually means noone is watching
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
echo "${DATA}" | grep -q '<MediaContainer size="0">'
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
# not found means that one or more medias are being played
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
elif [ ${RET} -eq 4 ]; then
|
||||||
|
# No response, assume not running
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
# We do not know what this means...
|
||||||
|
warn "Unknown response (${RET}) from server >>>"
|
||||||
|
warn "${DATA}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
verifyToken() {
|
||||||
|
wget -qO /dev/null "https://plex.tv/api/resources?X-Plex-Token=${TOKEN}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Shared functions
|
||||||
|
|
||||||
|
# SHARED
|
||||||
|
warn() {
|
||||||
|
echo "WARNING: $@" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
echo "$@" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
echo "ERROR: $@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Intentionally leaving this hard to find so that people aren't trying to use it manually.
|
||||||
|
if [ "$(basename "$0")" = "get-plex-token" ]; then
|
||||||
|
[ -f /etc/plexupdate.conf ] && source /etc/plexupdate.conf
|
||||||
|
getPlexToken && info "Token = $TOKEN"
|
||||||
|
fi
|
327
plexupdate.sh
327
plexupdate.sh
|
@ -6,17 +6,6 @@
|
||||||
# Server for Linux. It supports both the public versions
|
# Server for Linux. It supports both the public versions
|
||||||
# as well as the PlexPass versions.
|
# as well as the PlexPass versions.
|
||||||
#
|
#
|
||||||
# PlexPass users:
|
|
||||||
# Create a plexupdate.conf file in your home directory with these
|
|
||||||
# values:
|
|
||||||
#
|
|
||||||
# EMAIL='<whatever your plexpass email was>'
|
|
||||||
# PASS='<whatever password you used>'
|
|
||||||
# DOWNLOADDIR='<where you would like to save the downloaded package>'
|
|
||||||
#
|
|
||||||
# And run the tool using: ./plexupdate.sh --config plexupdate.conf
|
|
||||||
# or place the config in /etc/plexupdate.conf
|
|
||||||
#
|
|
||||||
# See https://github.com/mrworf/plexupdate for more details.
|
# See https://github.com/mrworf/plexupdate for more details.
|
||||||
#
|
#
|
||||||
# Returns 0 on success
|
# Returns 0 on success
|
||||||
|
@ -58,7 +47,6 @@ PLEXPORT=32400
|
||||||
# Defaults
|
# Defaults
|
||||||
# (aka "Advanced" settings, can be overriden with config file)
|
# (aka "Advanced" settings, can be overriden with config file)
|
||||||
FORCE=no
|
FORCE=no
|
||||||
FORCEALL=no
|
|
||||||
PUBLIC=no
|
PUBLIC=no
|
||||||
AUTOINSTALL=no
|
AUTOINSTALL=no
|
||||||
AUTODELETE=no
|
AUTODELETE=no
|
||||||
|
@ -71,48 +59,11 @@ CHECKUPDATE=yes
|
||||||
NOTIFY=no
|
NOTIFY=no
|
||||||
CHECKONLY=no
|
CHECKONLY=no
|
||||||
|
|
||||||
# Default options for package managers, override if needed
|
|
||||||
REDHAT_INSTALL="dnf -y install"
|
|
||||||
DEBIAN_INSTALL="dpkg -i"
|
|
||||||
DISTRO_INSTALL=""
|
|
||||||
|
|
||||||
# Current pages we need - Do not change unless Plex.tv changes again
|
|
||||||
URL_LOGIN='https://plex.tv/users/sign_in.json'
|
|
||||||
URL_DOWNLOAD='https://plex.tv/api/downloads/1.json?channel=plexpass'
|
|
||||||
URL_DOWNLOAD_PUBLIC='https://plex.tv/api/downloads/1.json'
|
|
||||||
|
|
||||||
#URL for new version check
|
|
||||||
UPSTREAM_GIT_URL='https://raw.githubusercontent.com/mrworf/plexupdate/master/plexupdate.sh'
|
|
||||||
|
|
||||||
#Branch to fetch updates from
|
|
||||||
BRANCHNAME="master"
|
|
||||||
|
|
||||||
#Files "owned" by plexupdate, for autoupdate
|
|
||||||
PLEXUPDATE_FILES="plexupdate.sh extras/installer.sh extras/cronwrapper"
|
|
||||||
|
|
||||||
FILE_POSTDATA=$(mktemp /tmp/plexupdate.postdata.XXXX)
|
|
||||||
FILE_RAW=$(mktemp /tmp/plexupdate.raw.XXXX)
|
|
||||||
FILE_FAILCAUSE=$(mktemp /tmp/plexupdate.failcause.XXXX)
|
|
||||||
FILE_KAKA=$(mktemp /tmp/plexupdate.kaka.XXXX)
|
|
||||||
FILE_SHA=$(mktemp /tmp/plexupdate.sha.XXXX)
|
FILE_SHA=$(mktemp /tmp/plexupdate.sha.XXXX)
|
||||||
FILE_WGETLOG=$(mktemp /tmp/plexupdate.wget.XXXX)
|
FILE_WGETLOG=$(mktemp /tmp/plexupdate.wget.XXXX)
|
||||||
FILE_LOCAL=$(mktemp /tmp/plexupdate.local.XXXX)
|
SCRIPT_PATH="$(dirname "$0")"
|
||||||
FILE_REMOTE=$(mktemp /tmp/plexupdate.remote.XXXX)
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Functions for rest of script
|
|
||||||
|
|
||||||
warn() {
|
|
||||||
echo "WARNING: $@" >&1
|
|
||||||
}
|
|
||||||
|
|
||||||
info() {
|
|
||||||
echo "$@" >&1
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
echo "ERROR: $@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $(basename $0) [-acdfFhlpPqsuU] [<long options>]"
|
echo "Usage: $(basename $0) [-acdfFhlpPqsuU] [<long options>]"
|
||||||
|
@ -122,7 +73,6 @@ usage() {
|
||||||
echo " -d Auto delete after auto install"
|
echo " -d Auto delete after auto install"
|
||||||
echo " -f Force download even if it's the same version or file"
|
echo " -f Force download even if it's the same version or file"
|
||||||
echo " already exists unless checksum passes"
|
echo " already exists unless checksum passes"
|
||||||
echo " -F Force download always"
|
|
||||||
echo " -h This help"
|
echo " -h This help"
|
||||||
echo " -l List available builds and distros"
|
echo " -l List available builds and distros"
|
||||||
echo " -p Public Plex Media Server version"
|
echo " -p Public Plex Media Server version"
|
||||||
|
@ -134,109 +84,32 @@ usage() {
|
||||||
echo " -v Show additional debug information"
|
echo " -v Show additional debug information"
|
||||||
echo ""
|
echo ""
|
||||||
echo " Long Argument Options:"
|
echo " Long Argument Options:"
|
||||||
|
echo " --check-update Check for new version of plex only"
|
||||||
echo " --config <path/to/config/file> Configuration file to use"
|
echo " --config <path/to/config/file> Configuration file to use"
|
||||||
echo " --dldir <path/to/download/dir> Download directory to use"
|
echo " --dldir <path/to/download/dir> Download directory to use"
|
||||||
echo " --email <plex.tv email> Plex.TV email address"
|
echo " --help This help"
|
||||||
echo " --pass <plex.tv password> Plex.TV password"
|
|
||||||
echo " --server <Plex server address> Address of Plex Server"
|
|
||||||
echo " --port <Plex server port> Port for Plex Server. Used with --server"
|
|
||||||
echo " --notify-success Set exit code 10 if update is available/installed"
|
echo " --notify-success Set exit code 10 if update is available/installed"
|
||||||
echo " --check-update Check for new version of plex only"
|
echo " --port <Plex server port> Port for Plex Server. Used with --server"
|
||||||
|
echo " --server <Plex server address> Address of Plex Server"
|
||||||
|
echo " --token Manually specify the token to use to download Plex Pass releases"
|
||||||
echo ""
|
echo ""
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
running() {
|
if ! source "${SCRIPT_PATH}/plexupdate-core"; then
|
||||||
local DATA="$(wget --no-check-certificate -q -O - https://$1:$3/status/sessions?X-Plex-Token=$2)"
|
echo "ERROR: plexupdate-core can't be found. Please redownload plexupdate and try again." >2
|
||||||
local RET=$?
|
exit 1
|
||||||
if [ ${RET} -eq 0 ]; then
|
fi
|
||||||
if [ -z "${DATA}" ]; then
|
|
||||||
# Odd, but usually means noone is watching
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
echo "${DATA}" | grep -q '<MediaContainer size="0">'
|
|
||||||
if [ $? -eq 1 ]; then
|
|
||||||
# not found means that one or more medias are being played
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
elif [ ${RET} -eq 4 ]; then
|
|
||||||
# No response, assume not running
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
# We do not know what this means...
|
|
||||||
warn "Unknown response (${RET}) from server >>>"
|
|
||||||
warn "${DATA}"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
trimQuotes() {
|
|
||||||
local __buffer=$1
|
|
||||||
|
|
||||||
# Remove leading single quote
|
|
||||||
__buffer=${__buffer#\'}
|
|
||||||
# Remove ending single quote
|
|
||||||
__buffer=${__buffer%\'}
|
|
||||||
|
|
||||||
echo $__buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
# Useful functions
|
|
||||||
rawurlencode() {
|
|
||||||
local string="${1}"
|
|
||||||
local strlen=${#string}
|
|
||||||
local encoded=""
|
|
||||||
|
|
||||||
for (( pos=0 ; pos<strlen ; pos++ )); do
|
|
||||||
c=${string:$pos:1}
|
|
||||||
case "$c" in
|
|
||||||
[-_.~a-zA-Z0-9] ) o="${c}" ;;
|
|
||||||
* ) printf -v o '%%%02x' "'$c"
|
|
||||||
esac
|
|
||||||
encoded+="${o}"
|
|
||||||
done
|
|
||||||
echo "${encoded}"
|
|
||||||
}
|
|
||||||
|
|
||||||
keypair() {
|
|
||||||
local key="$( rawurlencode "$1" )"
|
|
||||||
local val="$( rawurlencode "$2" )"
|
|
||||||
|
|
||||||
echo "${key}=${val}"
|
|
||||||
}
|
|
||||||
|
|
||||||
getPlexServerToken() {
|
|
||||||
if [ -f /etc/default/plexmediaserver ]; then
|
|
||||||
source /etc/default/plexmediaserver
|
|
||||||
fi
|
|
||||||
|
|
||||||
# List possible locations to find Plex Server preference file
|
|
||||||
local VALIDPATHS=("${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" "/var/lib/plexmediaserver/Library/Application Support/" "${HOME}/Library/Application Support/")
|
|
||||||
local PREFFILE="/Plex Media Server/Preferences.xml"
|
|
||||||
|
|
||||||
for I in "${VALIDPATHS[@]}" ; do
|
|
||||||
if [ ! -z "${I}" -a -f "${I}${PREFFILE}" ]; then
|
|
||||||
sed -n 's/.*PlexOnlineToken="\([[:alnum:]]*\).*".*/\1/p' "${I}${PREFFILE}" 2>/dev/null
|
|
||||||
if [ $? -ne 0 -a -z "${EMAIL}" -a -z "${PASS}" ]; then
|
|
||||||
error "Do not have permission to read token from Plex Server preference file (${I}${PREFFILE})"
|
|
||||||
fi
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Setup an exit handler so we cleanup
|
# Setup an exit handler so we cleanup
|
||||||
cleanup() {
|
cleanup() {
|
||||||
for F in "${FILE_RAW}" "${FILE_FAILCAUSE}" "${FILE_POSTDATA}" "${FILE_KAKA}" "${FILE_SHA}" "${FILE_LOCAL}" "${FILE_REMOTE}" "${FILE_WGETLOG}"; do
|
rm "${FILE_SHA}" "${FILE_WGETLOG}" &> /dev/null
|
||||||
rm "$F" 2>/dev/null >/dev/null
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
# Parse commandline
|
# Parse commandline
|
||||||
ALLARGS=( "$@" )
|
ALLARGS=( "$@" )
|
||||||
optstring="-o acCdfFhlpPqrSsuUv -l config:,dldir:,email:,pass:,server:,port:,notify-success,check-update"
|
optstring="-o acCdfFhlpPqrSsuUv -l config:,dldir:,email:,pass:,server:,port:,token:,notify-success,check-update,help"
|
||||||
GETOPTRES=$(getopt $optstring -- "$@")
|
GETOPTRES=$(getopt $optstring -- "$@")
|
||||||
if [ $? -eq 1 ]; then
|
if [ $? -eq 1 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -256,7 +129,7 @@ done
|
||||||
# We have to double-check that both files exist before trying to stat them. This is going away soon.
|
# We have to double-check that both files exist before trying to stat them. This is going away soon.
|
||||||
if [ -z "${CONFIGFILE}" -a -f ~/.plexupdate -a ! -f /etc/plexupdate.conf ] || \
|
if [ -z "${CONFIGFILE}" -a -f ~/.plexupdate -a ! -f /etc/plexupdate.conf ] || \
|
||||||
([ -f "${CONFIGFILE}" -a -f ~/.plexupdate ] && [ `stat -Lc %i "${CONFIGFILE}"` == `stat -Lc %i ~/.plexupdate` ]); then
|
([ -f "${CONFIGFILE}" -a -f ~/.plexupdate ] && [ `stat -Lc %i "${CONFIGFILE}"` == `stat -Lc %i ~/.plexupdate` ]); then
|
||||||
warn ".plexupdate has been deprecated. Please run $(dirname "$0")/extras/installer.sh to update your configuration."
|
warn ".plexupdate has been deprecated. Please run ${SCRIPT_PATH}/extras/installer.sh to update your configuration."
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
for i in `seq 1 5`; do echo -n .\ ; sleep 1; done
|
for i in `seq 1 5`; do echo -n .\ ; sleep 1; done
|
||||||
echo .
|
echo .
|
||||||
|
@ -277,7 +150,7 @@ do
|
||||||
(-C) error "CRON option is deprecated, please use cronwrapper (see README.md)"; exit 255;;
|
(-C) error "CRON option is deprecated, please use cronwrapper (see README.md)"; exit 255;;
|
||||||
(-d) AUTODELETE=yes;;
|
(-d) AUTODELETE=yes;;
|
||||||
(-f) FORCE=yes;;
|
(-f) FORCE=yes;;
|
||||||
(-F) FORCEALL=yes;;
|
(-F) error "FORCEALL/-F option is deprecated, please use FORCE/-f instead"; exit 255;;
|
||||||
(-l) LISTOPTS=yes;;
|
(-l) LISTOPTS=yes;;
|
||||||
(-p) PUBLIC=yes;;
|
(-p) PUBLIC=yes;;
|
||||||
(-P) SHOWPROGRESS=yes;;
|
(-P) SHOWPROGRESS=yes;;
|
||||||
|
@ -290,10 +163,12 @@ do
|
||||||
|
|
||||||
(--config) shift;; #gobble up the paramater and silently continue parsing
|
(--config) shift;; #gobble up the paramater and silently continue parsing
|
||||||
(--dldir) shift; DOWNLOADDIR=$(trimQuotes ${1});;
|
(--dldir) shift; DOWNLOADDIR=$(trimQuotes ${1});;
|
||||||
(--email) shift; EMAIL=$(trimQuotes ${1});;
|
(--email) shift; warn "EMAIL is deprecated. Use TOKEN instead."; EMAIL=$(trimQuotes ${1});;
|
||||||
(--pass) shift; PASS=$(trimQuotes ${1});;
|
(--pass) shift; warn "PASS is deprecated. Use TOKEN instead."; PASS=$(trimQuotes ${1});;
|
||||||
(--server) shift; PLEXSERVER=$(trimQuotes ${1});;
|
(--server) shift; PLEXSERVER=$(trimQuotes ${1});;
|
||||||
(--port) shift; PLEXPORT=$(trimQuotes ${1});;
|
(--port) shift; PLEXPORT=$(trimQuotes ${1});;
|
||||||
|
(--token) shift; TOKEN=$(trimQuotes ${1});;
|
||||||
|
(--help) usage;;
|
||||||
|
|
||||||
(--notify-success) NOTIFY=yes;;
|
(--notify-success) NOTIFY=yes;;
|
||||||
(--check-update) CHECKONLY=yes;;
|
(--check-update) CHECKONLY=yes;;
|
||||||
|
@ -329,6 +204,11 @@ if [ "${KEEP}" = "yes" ]; then
|
||||||
exit 255
|
exit 255
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "${FORCEALL}" = "yes" ]; then
|
||||||
|
error "FORCEALL is deprecated, please use FORCE instead"
|
||||||
|
exit 255
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -z "${RELEASE}" ]; then
|
if [ ! -z "${RELEASE}" ]; then
|
||||||
error "RELEASE keyword is deprecated and should be removed from config file"
|
error "RELEASE keyword is deprecated and should be removed from config file"
|
||||||
error "Use DISTRO and BUILD instead to manually select what to install (check README.md)"
|
error "Use DISTRO and BUILD instead to manually select what to install (check README.md)"
|
||||||
|
@ -341,7 +221,7 @@ if [ "${AUTOUPDATE}" = "yes" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pushd "$(dirname "$0")" >/dev/null
|
pushd "${SCRIPT_PATH}" >/dev/null
|
||||||
|
|
||||||
if [ ! -d .git ]; then
|
if [ ! -d .git ]; then
|
||||||
warn "This is not a git repository. Auto-update only works if you've done a git clone"
|
warn "This is not a git repository. Auto-update only works if you've done a git clone"
|
||||||
|
@ -440,101 +320,36 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${CHECKUPDATE}" = "yes" -a "${AUTOUPDATE}" = "no" ]; then
|
if [ "${CHECKUPDATE}" = "yes" -a "${AUTOUPDATE}" = "no" ]; then
|
||||||
(wget -q "$UPSTREAM_GIT_URL" -O - 2>/dev/null || echo ERROR) | sha1sum >"${FILE_REMOTE}" 2>/dev/null
|
pushd "${SCRIPT_PATH}" > /dev/null
|
||||||
ERR1=$?
|
for filename in $PLEXUPDATE_FILES; do
|
||||||
(cat "$0" 2>/dev/null || echo ERROR) | sha1sum >"${FILE_LOCAL}" 2>/dev/null
|
[ -f "$filename" ] || error "Update check failed. '$filename' could not be found"
|
||||||
ERR2=$?
|
|
||||||
if [ $ERR1 -ne 0 -o $ERR2 -ne 0 ]; then
|
REMOTE_SHA=$(getRemoteSHA "$UPSTREAM_GIT_URL/$filename") || error "Update check failed. Unable to fetch '$UPSTREAM_GIT_URL/$filename'."
|
||||||
error "When checking for version, was unable to confirm version of script"
|
LOCAL_SHA=$(getLocalSHA "$filename")
|
||||||
else
|
if [ "$REMOTE_SHA" != "$LOCAL_SHA" ]; then
|
||||||
# "709c7506b17090bce0d1e2464f39f4a434cf25f1" is the hash for "ERROR" :)
|
info "Newer version of this script is available at https://github.com/${GIT_OWNER:-mrworf}/plexupdate"
|
||||||
if grep -sq "709c7506b17090bce0d1e2464f39f4a434cf25f1" "${FILE_LOCAL}" ; then
|
break
|
||||||
error "When checking for version, was unable to validate local copy"
|
|
||||||
elif grep -sq "709c7506b17090bce0d1e2464f39f4a434cf25f1" "${FILE_REMOTE}" ; then
|
|
||||||
error "When checking for version, was was unable to validate remote copy"
|
|
||||||
elif ! diff "${FILE_LOCAL}" "${FILE_REMOTE}" >/dev/null 2>/dev/null ; then
|
|
||||||
info "Newer version of this script is available at https://github.com/mrworf/plexupdate"
|
|
||||||
fi
|
fi
|
||||||
fi
|
done
|
||||||
rm "${FILE_LOCAL}" 2>/dev/null >/dev/null
|
popd > /dev/null
|
||||||
rm "${FILE_REMOTE}" 2>/dev/null >/dev/null
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fields we need to submit for login to work
|
if [ "${PUBLIC}" = "no" -a -z "$TOKEN" ]; then
|
||||||
#
|
TO_SOURCE="$(dirname "$0")/extras/get-plex-token"
|
||||||
# Field Value
|
[ -f "$TO_SOURCE" ] && source $TO_SOURCE
|
||||||
# utf8 ✓
|
if ! getPlexToken; then
|
||||||
# authenticity_token <Need to be obtained from web page>
|
error "Unable to get Plex token, falling back to public release"
|
||||||
# user[login] $EMAIL
|
PUBLIC="yes"
|
||||||
# user[password] $PASSWORD
|
|
||||||
# user[remember_me] 0
|
|
||||||
# commit Sign in
|
|
||||||
|
|
||||||
if [ "${PUBLIC}" = "no" ]; then
|
|
||||||
# Clean old session
|
|
||||||
rm "${FILE_KAKA}" 2>/dev/null
|
|
||||||
|
|
||||||
# Try to obtain token from Plex Server Installation
|
|
||||||
TOKEN=
|
|
||||||
if [ -z "${EMAIL}" -o -z "${PASS}" ]; then
|
|
||||||
TOKEN=$(getPlexServerToken)
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "${TOKEN}" ]; then
|
if [ "$PUBLIC" != "no" ]; then
|
||||||
# If no token, go through regular process
|
# It's a public version, so change URL
|
||||||
if [ -z "${EMAIL}" -o -z "${PASS}" ]; then
|
|
||||||
error "Need username & password to download PlexPass version. Otherwise run with -p to download public version."
|
|
||||||
exit 1
|
|
||||||
elif [ ! -z "${EMAIL}" ] && [[ "$EMAIL" == *"@"* ]] && [[ "$EMAIL" != *"@"*"."* ]]; then
|
|
||||||
error "EMAIL field must contain a valid email address"
|
|
||||||
exit 1
|
|
||||||
elif [ ! -z "${EMAIL}" -a ! -z "${PASS}" -a "${PUBLIC}" = "yes" ]; then
|
|
||||||
warn "You have defined email and password but PUBLIC is set to yes, this will not download the PlexPass version"
|
|
||||||
fi
|
|
||||||
info "Authenticating with plex.tv using email and password"
|
|
||||||
|
|
||||||
# Build post data
|
|
||||||
echo -ne >"${FILE_POSTDATA}" "$(keypair "user[login]" "${EMAIL}" )"
|
|
||||||
echo -ne >>"${FILE_POSTDATA}" "&$(keypair "user[password]" "${PASS}" )"
|
|
||||||
echo -ne >>"${FILE_POSTDATA}" "&$(keypair "user[remember_me]" "0" )"
|
|
||||||
|
|
||||||
# Authenticate (using Plex Single Sign On)
|
|
||||||
wget --header "X-Plex-Client-Identifier: 4a745ae7-1839-e44e-1e42-aebfa578c865" --header "X-Plex-Product: Plex SSO" --load-cookies "${FILE_KAKA}" --save-cookies "${FILE_KAKA}" --keep-session-cookies "${URL_LOGIN}" --post-file="${FILE_POSTDATA}" -q -S -O "${FILE_FAILCAUSE}" 2>"${FILE_RAW}"
|
|
||||||
# Delete authentication data ... Bad idea to let that stick around
|
|
||||||
rm "${FILE_POSTDATA}"
|
|
||||||
|
|
||||||
# Provide some details to the end user
|
|
||||||
RESULTCODE=$(head -n1 "${FILE_RAW}" | grep -oe '[1-5][0-9][0-9]')
|
|
||||||
if [ $RESULTCODE -eq 401 ]; then
|
|
||||||
error "Username and/or password incorrect"
|
|
||||||
if [ "$VERBOSE" = "yes" ]; then
|
|
||||||
info "Tried using \"${EMAIL}\" and \"${PASS}\" "
|
|
||||||
fi
|
|
||||||
exit 1
|
|
||||||
elif [ $RESULTCODE -ne 201 ]; then
|
|
||||||
error "Failed to login, debug information:"
|
|
||||||
cat "${FILE_RAW}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If the system got here, it means the login was successfull, so we set the TOKEN variable to the authToken from the response
|
|
||||||
# I use cut -c 14- to cut off the "authToken":" string from the grepped result, can probably be done in a different way
|
|
||||||
TOKEN=$(<"${FILE_FAILCAUSE}" grep -ioe '"authToken":"[^"]*' | cut -c 14-)
|
|
||||||
|
|
||||||
# Remove this, since it contains more information than we should leave hanging around
|
|
||||||
rm "${FILE_FAILCAUSE}"
|
|
||||||
else
|
|
||||||
info "Using Plex Server credentials to authenticate"
|
|
||||||
fi
|
|
||||||
elif [ "$PUBLIC" != "no" ]; then
|
|
||||||
# It's a public version, so change URL and make doubly sure that cookies are empty
|
|
||||||
rm 2>/dev/null >/dev/null "${FILE_KAKA}"
|
|
||||||
touch "${FILE_KAKA}"
|
|
||||||
URL_DOWNLOAD=${URL_DOWNLOAD_PUBLIC}
|
URL_DOWNLOAD=${URL_DOWNLOAD_PUBLIC}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${LISTOPTS}" = "yes" ]; then
|
if [ "${LISTOPTS}" = "yes" ]; then
|
||||||
opts="$(wget --load-cookies "${FILE_KAKA}" --save-cookies "${FILE_KAKA}" --keep-session-cookies "${URL_DOWNLOAD}" -O - 2>/dev/null | grep -oe '"label"[^}]*' | grep -v Download | sed 's/"label":"\([^"]*\)","build":"\([^"]*\)","distro":"\([^"]*\)".*/"\3" "\2" "\1"/' | uniq | sort)"
|
opts="$(wget "${URL_DOWNLOAD}" -O - 2>/dev/null | grep -oe '"label"[^}]*' | grep -v Download | sed 's/"label":"\([^"]*\)","build":"\([^"]*\)","distro":"\([^"]*\)".*/"\3" "\2" "\1"/' | uniq | sort)"
|
||||||
eval opts=( "DISTRO" "BUILD" "DESCRIPTION" "======" "=====" "==============================================" $opts )
|
eval opts=( "DISTRO" "BUILD" "DESCRIPTION" "======" "=====" "==============================================" $opts )
|
||||||
|
|
||||||
BUILD=
|
BUILD=
|
||||||
|
@ -558,10 +373,16 @@ fi
|
||||||
info "Retrieving list of available distributions"
|
info "Retrieving list of available distributions"
|
||||||
|
|
||||||
# Set "X-Plex-Token" to the auth token, if no token is specified or it is invalid, the list will return public downloads by default
|
# Set "X-Plex-Token" to the auth token, if no token is specified or it is invalid, the list will return public downloads by default
|
||||||
RELEASE=$(wget --header "X-Plex-Token:"${TOKEN}"" --load-cookies "${FILE_KAKA}" --save-cookies "${FILE_KAKA}" --keep-session-cookies "${URL_DOWNLOAD}" -O - 2>/dev/null | grep -ioe '"label"[^}]*' | grep -i "\"distro\":\"${DISTRO}\"" | grep -m1 -i "\"build\":\"${BUILD}\"")
|
RELEASE=$(wget --header "X-Plex-Token:"${TOKEN}"" "${URL_DOWNLOAD}" -O - 2>/dev/null | grep -ioe '"label"[^}]*' | grep -i "\"distro\":\"${DISTRO}\"" | grep -m1 -i "\"build\":\"${BUILD}\"")
|
||||||
DOWNLOAD=$(echo ${RELEASE} | grep -m1 -ioe 'https://[^\"]*')
|
DOWNLOAD=$(echo ${RELEASE} | grep -m1 -ioe 'https://[^\"]*')
|
||||||
CHECKSUM=$(echo ${RELEASE} | grep -ioe '\"checksum\"\:\"[^\"]*' | sed 's/\"checksum\"\:\"//')
|
CHECKSUM=$(echo ${RELEASE} | grep -ioe '\"checksum\"\:\"[^\"]*' | sed 's/\"checksum\"\:\"//')
|
||||||
|
|
||||||
|
if [ "$VERBOSE" = "yes" ]; then
|
||||||
|
for i in RELEASE DOWNLOAD CHECKSUM; do
|
||||||
|
info "$i=${!i}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "${DOWNLOAD}" ]; then
|
if [ -z "${DOWNLOAD}" ]; then
|
||||||
error "Unable to retrieve the URL needed for download (Query DISTRO: $DISTRO, BUILD: $BUILD)"
|
error "Unable to retrieve the URL needed for download (Query DISTRO: $DISTRO, BUILD: $BUILD)"
|
||||||
if [ ! -z "${RELEASE}" ]; then
|
if [ ! -z "${RELEASE}" ]; then
|
||||||
|
@ -569,6 +390,9 @@ if [ -z "${DOWNLOAD}" ]; then
|
||||||
error "Please try https://plex.tv and confirm it works there before reporting this issue"
|
error "Please try https://plex.tv and confirm it works there before reporting this issue"
|
||||||
fi
|
fi
|
||||||
exit 3
|
exit 3
|
||||||
|
elif [ -z "${CHECKSUM}" ]; then
|
||||||
|
error "Unable to retrieve a checksum for the download. Please try https://plex.tv/downloads before reporting this issue."
|
||||||
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FILENAME="$(basename 2>/dev/null ${DOWNLOAD})"
|
FILENAME="$(basename 2>/dev/null ${DOWNLOAD})"
|
||||||
|
@ -605,48 +429,32 @@ if [ "${CHECKONLY}" = "yes" ]; then
|
||||||
info "Your OS reports Plex $INSTALLED_VERSION installed, newer version is available (${AVAIL})"
|
info "Your OS reports Plex $INSTALLED_VERSION installed, newer version is available (${AVAIL})"
|
||||||
exit 7
|
exit 7
|
||||||
else
|
else
|
||||||
info "You are running latest version of Plex (${INSTALLED_VERSION})"
|
info "You are running the latest version of Plex (${INSTALLED_VERSION})"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $FILENAME == *$INSTALLED_VERSION* ]] && [ "${FORCE}" != "yes" -a "${FORCEALL}" != "yes" ] && [ ! -z "${INSTALLED_VERSION}" ]; then
|
if [[ $FILENAME == *$INSTALLED_VERSION* ]] && [ "${FORCE}" != "yes" ] && [ ! -z "${INSTALLED_VERSION}" ]; then
|
||||||
info "Your OS reports the latest version of Plex ($INSTALLED_VERSION) is already installed. Use -f to force download."
|
info "Your OS reports the latest version of Plex ($INSTALLED_VERSION) is already installed. Use -f to force download."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "${DOWNLOADDIR}/${FILENAME}" ]; then
|
if [ -f "${DOWNLOADDIR}/${FILENAME}" -a "${FORCE}" != "yes" ]; then
|
||||||
if [ "${FORCE}" != "yes" -a "${FORCEALL}" != "yes" ]; then
|
if sha1sum --status -c "${FILE_SHA}"; then
|
||||||
sha1sum --status -c "${FILE_SHA}"
|
info "File already exists (${FILENAME}), won't download."
|
||||||
if [ $? -eq 0 ]; then
|
if [ "${AUTOINSTALL}" != "yes" ]; then
|
||||||
info "File already exists (${FILENAME}), won't download."
|
exit 0
|
||||||
if [ "${AUTOINSTALL}" != "yes" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
SKIP_DOWNLOAD="yes"
|
|
||||||
else
|
|
||||||
info "File exists but fails checksum. Redownloading."
|
|
||||||
SKIP_DOWNLOAD="no"
|
|
||||||
fi
|
fi
|
||||||
elif [ "${FORCEALL}" == "yes" ]; then
|
SKIP_DOWNLOAD="yes"
|
||||||
info "Note! File exists, but asked to overwrite with new copy"
|
|
||||||
else
|
else
|
||||||
sha1sum --status -c "${FILE_SHA}"
|
info "File exists but fails checksum. Redownloading."
|
||||||
if [ $? -ne 0 ]; then
|
SKIP_DOWNLOAD="no"
|
||||||
info "File exists but fails checksum. Redownloading."
|
|
||||||
else
|
|
||||||
info "File exists and checksum passes, won't redownload."
|
|
||||||
if [ "${AUTOINSTALL}" != "yes" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
SKIP_DOWNLOAD="yes"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${SKIP_DOWNLOAD}" = "no" ]; then
|
if [ "${SKIP_DOWNLOAD}" = "no" ]; then
|
||||||
info "Downloading release \"${FILENAME}\""
|
info "Downloading release \"${FILENAME}\""
|
||||||
wget ${WGETOPTIONS} -o "${FILE_WGETLOG}" --load-cookies "${FILE_KAKA}" --save-cookies "${FILE_KAKA}" --keep-session-cookies "${DOWNLOAD}" -O "${DOWNLOADDIR}/${FILENAME}" 2>&1
|
wget ${WGETOPTIONS} -o "${FILE_WGETLOG}" "${DOWNLOAD}" -O "${DOWNLOADDIR}/${FILENAME}" 2>&1
|
||||||
CODE=$?
|
CODE=$?
|
||||||
|
|
||||||
if [ ${CODE} -ne 0 ]; then
|
if [ ${CODE} -ne 0 ]; then
|
||||||
|
@ -657,8 +465,7 @@ if [ "${SKIP_DOWNLOAD}" = "no" ]; then
|
||||||
info "File downloaded"
|
info "File downloaded"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sha1sum --status -c "${FILE_SHA}"
|
if ! sha1sum --status -c "${FILE_SHA}"; then
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
error "Downloaded file corrupt. Try again."
|
error "Downloaded file corrupt. Try again."
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue