mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-08-20 21:33:16 -07:00
Installer script and cleanup
* Stop users from saving config with invalid download directory * Added additional sanity for email checking * Add installer script * Update cronwrapper to work with installer script * Add AUTOUPDATE to default config * Read /etc/plexupdate.conf before other configs, if available * Use dnf on newer redhat systems * Only use plexupdate.conf or --config * Give existing users explaination as to why plexupdate.sh failed * Removed references to .plexupdate * Warn users that .plexupdate is going away * Offer to import settings in ~/.plexupdate.conf in installer (if they exist) * Only show AUTOSTART warning if AUTOINSTALL is enabled * Change default download directory to /tmp * Warn users to run the installer as sudo * Remove VAR_CL logic in favor of checking config before getopt run * Use sha1sum for version check and auto-fix git permissions on exit * Skip update check if AUTOUPDATE is enabled * Fix permissions for all files, not just .git * Don't enable -P in installer if we know it won't work
This commit is contained in:
parent
fa7ef1da94
commit
939ab6f436
4 changed files with 831 additions and 573 deletions
158
README.md
158
README.md
|
@ -1,16 +1,38 @@
|
||||||

|

|
||||||
# plexupdate
|
# plexupdate
|
||||||
|
|
||||||
Plex Update is a BASH script which simplifies the life of headless Linux Plex Media Server users (how's that for a strange description).
|
Plex Update is a bash script which helps you keep Plex Media Server up to date on Linux.
|
||||||
|
|
||||||
This tool will automatically download the latest version for linux (Using plexpass or public version) and if you **kindly ask**, also install it for you.
|
plexupdate will automatically download the latest version of Plex Media Server for Linux and, optionally, also install it for you.
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
It's fairly easy, but let's take it step by step (if it seems too much, skip to the end for a short version)
|
In the old days, this used to be a bit of a chore. But no more!
|
||||||
|
|
||||||
|
```
|
||||||
|
bash -c "$(wget -O - https://raw.githubusercontent.com/mrworf/plexupdate/master/extras/installer.sh)"
|
||||||
|
```
|
||||||
|
|
||||||
|
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 have any trouble with the installer, or would just prefer to set plexupdate up manually, read on.
|
||||||
|
|
||||||
## 1. Getting the code
|
## 1. Getting the code
|
||||||
|
|
||||||
|
####Using git to clone (recommended)
|
||||||
|
```
|
||||||
|
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).
|
||||||
|
|
||||||
####Using wget and unzip
|
####Using wget and unzip
|
||||||
|
|
||||||
Download it as a [zip file](https://github.com/mrworf/plexupdate/archive/master.zip) and unzip it on your server.
|
Download it as a [zip file](https://github.com/mrworf/plexupdate/archive/master.zip) and unzip it on your server.
|
||||||
|
@ -19,33 +41,71 @@ wget https://github.com/mrworf/plexupdate/archive/master.zip && unzip master.zip
|
||||||
```
|
```
|
||||||
Note that unzip is required (`sudo apt-get install unzip`).
|
Note that unzip is required (`sudo apt-get install unzip`).
|
||||||
|
|
||||||
####Using git to clone (Recommended)
|
|
||||||
Using git is way easier and recommended, if you ask me.
|
|
||||||
```
|
|
||||||
git clone https://github.com/mrworf/plexupdate.git
|
|
||||||
```
|
|
||||||
Note that git is required (`sudo apt-get install git`)
|
|
||||||
|
|
||||||
The main benefit with git clone is that you can update to latest version very easily. If you want to use the auto update feature, you must be using a git clone.
|
|
||||||
|
|
||||||
## 2. Setting it up
|
## 2. Setting it up
|
||||||
|
|
||||||
To quickly setup plexupdate.sh, you should run it the first time like below:
|
In order to use `plexupdate.sh`, it's recommended you create a configuration file.
|
||||||
|
|
||||||
```
|
```
|
||||||
./plexupdate.sh --email='my.email@plex-server.com' --pass='my-secret-plex-password' --dldir='/a/folder/to/save/the/files/in' --saveconfig
|
sudo nano -w /etc/plexupdate.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
Obviously you need to change these so they match your account information. And if you don't put anything as for the ```--dldir``` option, the tool will use the folder you're executing the script from. So take care.
|
In the newly opened editor, insert the following (and make *sure* to change email and password)
|
||||||
|
|
||||||
## 3. Advanced options
|
```
|
||||||
|
EMAIL='john.doe@void.com'
|
||||||
|
PASS='verySecretPassword'
|
||||||
|
DOWNLOADDIR='/tmp/'
|
||||||
|
```
|
||||||
|
|
||||||
You can point out a different file than ```.plexupdate``` by providing it as the argument to the ```--config``` option. Any options set by the config file can be overridden with command-line options.
|
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.
|
There are also a few additional options for the more enterprising user. Setting any of these to `yes` will enable the function.
|
||||||
|
|
||||||
- CHECKUPDATE
|
- 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.
|
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
|
- 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
|
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
|
- PLEXPORT
|
||||||
|
@ -57,7 +117,7 @@ There are also a few additional options for the more enterprising user. Setting
|
||||||
- AUTODELETE
|
- AUTODELETE
|
||||||
Once successfully downloaded and installed, it will delete the package (want not, waste not? ;-))
|
Once successfully downloaded and installed, it will delete the package (want not, waste not? ;-))
|
||||||
- PUBLIC
|
- PUBLIC
|
||||||
The default behavior of plexupdate.sh is to download the PlexPass edition of Plex Media Center. 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.
|
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
|
- 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
|
- FORCEALL
|
||||||
|
@ -72,69 +132,43 @@ There are also a few additional options for the more enterprising user. Setting
|
||||||
|
|
||||||
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...
|
||||||
|
|
||||||
### Using it from CRON
|
|
||||||
|
|
||||||
If you want to use plexupdate as either a cron job or as a [systemd job](https://github.com/mrworf/plexupdate/wiki/Running-plexupdate-daily-as-a-systemd-timer), the -c option should do what you want. All non-error exit codes will be set to 0 and no output will be printed to stdout unless something has actually been done. (a new version was downloaded, installed, etc)
|
|
||||||
|
|
||||||
If you don't even want to know when something has been done, you can combine this with the -q option and you will only receive output in the event of an error. Everything else will just silently finish without producing any output.
|
|
||||||
|
|
||||||
### Command Line Options
|
### Command Line Options
|
||||||
|
|
||||||
Several new command line options are available. They can be specified in any order.
|
Plexupdate comes with many command line options. For the most up-to-date list, I'd recommend you run plexupdate.sh with -h
|
||||||
|
|
||||||
- ```--config <path/to/config/file>```
|
But here are some of the more useful ones:
|
||||||
|
|
||||||
|
- `--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 <Plex.tv email>`
|
||||||
Email to sign in to Plex.tv
|
Email to sign in to Plex.tv
|
||||||
- ```--pass <Plex.tv password>```
|
- `--pass <Plex.tv password>`
|
||||||
Password to sign in to Plex.tv
|
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>`
|
||||||
This is the address that Plex Media Server is on. Setting this will enable a check to see if users are on the server prior to the software being updated.
|
This is the address that Plex Media Server is on. Setting this will enable a check to see if users are on the server prior to the software being updated.
|
||||||
- ```--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.
|
||||||
- ```--saveconfig```
|
|
||||||
Saves the configuration as it is currently. This will take whatever is in the config file, plus whatever is specified on the command line and will save the config file with that information. Any information in the config file that plexupdate.sh does not understand or use WILL BE LOST.
|
|
||||||
|
|
||||||
### Logs
|
|
||||||
|
|
||||||
The script now outputs everything to a file (by default `/tmp/plexupdate.log`). This log ***MAY*** contain passwords, so if you post it online, ***USE CAUTION***.
|
|
||||||
|
|
||||||
To change the default log file, you can specify a new location:
|
|
||||||
|
|
||||||
```FILE_STDOUTLOG="<new/path/to/log>" ./plexupdate.sh <options>```
|
|
||||||
|
|
||||||
# Running it
|
|
||||||
|
|
||||||
It's very simple, just execute the tool once configured. It will complain if you've forgotten to set it up. If you want to use the autoinstall (-a option or `AUTOINSTALL=YES` is set), you must run as root or use sudo when executing or plexupdate.sh will stop and give you an error.
|
|
||||||
|
|
||||||
Overall it tries to give you hints regarding why it isn't doing what you expected it to.
|
|
||||||
|
|
||||||
# Trivia
|
# Trivia
|
||||||
|
|
||||||
- "kaka" is Swedish for "cookie"
|
- "kaka" is Swedish for "cookie"
|
||||||
|
|
||||||
# TL;DR
|
|
||||||
Open a terminal or SSH on the server running Plex Media Center
|
|
||||||
## First install
|
|
||||||
```
|
|
||||||
git clone https://github.com/mrworf/plexupdate.git
|
|
||||||
sudo plexupdate/plexupdate.sh -p -a
|
|
||||||
```
|
|
||||||
## Updating Plex and the script
|
|
||||||
```
|
|
||||||
sudo plexupdate/plexupdate.sh -p -u -a
|
|
||||||
```
|
|
||||||
|
|
||||||
# FAQ
|
# FAQ
|
||||||
|
|
||||||
## What username and password are you talking about
|
## Where is `.plexupdate`
|
||||||
|
|
||||||
The username and password for http://plex.tv
|
See explanation in the top of this document.
|
||||||
|
|
||||||
|
## What email and password are you talking about
|
||||||
|
|
||||||
|
The email and password for http://plex.tv
|
||||||
|
|
||||||
## My password is rejected even though correct
|
## 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 (`"`).
|
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
|
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.
|
||||||
|
|
71
extras/cronwrapper
Executable file
71
extras/cronwrapper
Executable file
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Script to be placed in one of
|
||||||
|
# /etc/cron.daily
|
||||||
|
# /etc/cron.weekly
|
||||||
|
#
|
||||||
|
# or called directly via /etc/crontab
|
||||||
|
#
|
||||||
|
# Do NOT rename it so it has a dot "." in the name, this will cause
|
||||||
|
# ubuntu (and perhaps other distros) to ignore it.
|
||||||
|
#
|
||||||
|
# CONF is used to point out a configuration file (optional)
|
||||||
|
# SCRIPT points out where to find plexupdate.sh
|
||||||
|
# LOGGING if true, logs all output to syslog daemon facility
|
||||||
|
# (typically /var/log/daemon.log or /var/log/syslog)
|
||||||
|
#
|
||||||
|
# Set CONFIGURED to true once you've setup the previous three
|
||||||
|
# options.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
if [ ! -f /etc/plexupdate.cron.conf ]; then
|
||||||
|
echo "ERROR: You have not configured /etc/plexupdate.cron.conf" >&2
|
||||||
|
exit 255
|
||||||
|
else
|
||||||
|
source /etc/plexupdate.cron.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${SCRIPT}" -o ! -f "${SCRIPT}" ]; then
|
||||||
|
echo "ERROR: Cannot find plexupdate.sh (tried ${SCRIPT})" >&2
|
||||||
|
exit 255
|
||||||
|
elif [ ${EUID} -eq 0 ]; then
|
||||||
|
UNSAFE_FILES=$(find -L "$(dirname "${SCRIPT}")" -perm /002 -or -not -uid 0 -or -not -gid 0)
|
||||||
|
if [ ! -z "${UNSAFE_FILES}" ]; then
|
||||||
|
echo "ERROR: Permissions on some files are too lax for running as root. Files must be owned by root:root and not world-writeable." >&2
|
||||||
|
echo "Unsafe files found:" >&2
|
||||||
|
echo "${UNSAFE_FILES}" >&2
|
||||||
|
exit 255
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$CONF" ]; then
|
||||||
|
# We have a config file, prefix it with parameter
|
||||||
|
if [ ! -f "${CONF}" ]; then
|
||||||
|
echo "ERROR: Cannot find config file (tried ${CONF})" >&2
|
||||||
|
exit 255
|
||||||
|
fi
|
||||||
|
CONF="--config=${CONF}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
LOGFILE=$(mktemp /tmp/plexupdate.cron.XXXX)
|
||||||
|
|
||||||
|
RET=0
|
||||||
|
if $LOGGING; then
|
||||||
|
"${SCRIPT}" "${CONF}" 2>&1 | tee ${LOGFILE} | logger -t plexupdate -p daemon.info
|
||||||
|
RET="${PIPESTATUS[0]}"
|
||||||
|
else
|
||||||
|
"${SCRIPT}" "${CONF}" >${LOGFILE} 2>&1
|
||||||
|
RET=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $RET -ne 2 -a $RET -ne 5 ]; then
|
||||||
|
# Make sure user gets an email about this
|
||||||
|
cat ${LOGFILE} >&2
|
||||||
|
else
|
||||||
|
# Nah, not important
|
||||||
|
RET=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm "${LOGFILE}" 2>/dev/null
|
||||||
|
exit $RET
|
346
extras/installer.sh
Executable file
346
extras/installer.sh
Executable file
|
@ -0,0 +1,346 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ORIGIN_REPO="https://github.com/mrworf/plexupdate"
|
||||||
|
FULL_PATH="/opt/plexupdate"
|
||||||
|
CONFIGFILE="/etc/plexupdate.conf"
|
||||||
|
CONFIGCRON="/etc/plexupdate.cron.conf"
|
||||||
|
CRONWRAPPER="/etc/cron.daily/plexupdate"
|
||||||
|
|
||||||
|
# default options
|
||||||
|
AUTOINSTALL=yes
|
||||||
|
AUTOUPDATE=yes
|
||||||
|
PUBLIC=
|
||||||
|
|
||||||
|
install() {
|
||||||
|
echo "'$req' is required but not installed, attempting to install..."
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
[ -z "$DISTRO_INSTALL" ] && check_distro
|
||||||
|
|
||||||
|
if [ $EUID -ne 0 ]; then
|
||||||
|
sudo $DISTRO_INSTALL $1 || abort "Failed while trying to install '$1'. Please install it manually and try again."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_distro() {
|
||||||
|
if [ -f /etc/redhat-release ] && hash dnf 2>/dev/null; then
|
||||||
|
DISTRO="redhat"
|
||||||
|
DISTRO_INSTALL="dnf -y install"
|
||||||
|
elif [ -f /etc/redhat-release ] && hash yum 2>/dev/null; then
|
||||||
|
DISTRO="redhat" #or CentOS but functionally the same
|
||||||
|
DISTRO_INSTALL="yum -y install"
|
||||||
|
elif hash apt 2>/dev/null; then
|
||||||
|
DISTRO="debian" #or Ubuntu
|
||||||
|
DISTRO_INSTALL="apt install"
|
||||||
|
elif hash apt-get 2>/dev/null; then
|
||||||
|
DISTRO="debian"
|
||||||
|
DISTRO_INSTALL="apt-get install"
|
||||||
|
else
|
||||||
|
DISTRO="unknown"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
yesno() {
|
||||||
|
case "$1" in
|
||||||
|
"")
|
||||||
|
default="Y"
|
||||||
|
;;
|
||||||
|
yes)
|
||||||
|
default="Y"
|
||||||
|
;;
|
||||||
|
true)
|
||||||
|
default="Y"
|
||||||
|
;;
|
||||||
|
no)
|
||||||
|
default="N"
|
||||||
|
;;
|
||||||
|
false)
|
||||||
|
default="N"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
default="$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
default="$(tr "[:lower:]" "[:upper:]" <<< "$default")"
|
||||||
|
if [ "$default" == "Y" ]; then
|
||||||
|
prompt="[Y/n] "
|
||||||
|
else
|
||||||
|
prompt="[N/y] "
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -n 1 -p "$prompt" answer
|
||||||
|
answer=${answer:-$default}
|
||||||
|
answer="$(tr "[:lower:]" "[:upper:]" <<< "$answer")"
|
||||||
|
|
||||||
|
if [ "$answer" == "Y" ]; then
|
||||||
|
echo
|
||||||
|
return 0
|
||||||
|
elif [ "$answer" == "N" ]; then
|
||||||
|
echo
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
noyes() {
|
||||||
|
yesno N
|
||||||
|
}
|
||||||
|
|
||||||
|
abort() {
|
||||||
|
echo "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
install_plexupdate() {
|
||||||
|
echo
|
||||||
|
read -e -p "Directory to install into: " -i "/opt/plexupdate" FULL_PATH
|
||||||
|
|
||||||
|
while [[ "$FULL_PATH" == *"~"* ]]; do
|
||||||
|
echo "Using '~' in your path can cause problems, please type out the full path instead"
|
||||||
|
echo
|
||||||
|
read -e -p "Directory to install into: " -i "/opt/plexupdate" FULL_PATH
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "$FULL_PATH" ]; then
|
||||||
|
echo -n "'$FULL_PATH' doesn't exist, attempting to create... "
|
||||||
|
if ! mkdir -p "$FULL_PATH" 2>/dev/null; then
|
||||||
|
sudo mkdir -p "$FULL_PATH" || abort "failed, cannot continue"
|
||||||
|
sudo chown $(id -un):$(id -gn) "$FULL_PATH" || abort "failed, cannot continue"
|
||||||
|
fi
|
||||||
|
echo "done"
|
||||||
|
elif [ ! -w "$FULL_PATH" ]; then
|
||||||
|
echo -n "'$FULL_PATH' exists, but you don't have permission to write to it. Changing owner... "
|
||||||
|
sudo chown $(id -un):$(id -gn) "$FULL_PATH" || abort "failed, cannot continue"
|
||||||
|
echo "done"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "${FULL_PATH}/.git" ]; then
|
||||||
|
cd "$FULL_PATH"
|
||||||
|
if git remote -v 2>/dev/null | grep -q "plexupdate"; then
|
||||||
|
echo -n "Found existing plexupdate repository in '$FULL_PATH', updating... "
|
||||||
|
git pull &>/dev/null || abort "Unknown error while updating, please check '$FULL_PATH' and then try again."
|
||||||
|
else
|
||||||
|
abort "'$FULL_PATH' appears to contain a different git repository, cannot continue"
|
||||||
|
fi
|
||||||
|
echo "done"
|
||||||
|
cd - &> /dev/null
|
||||||
|
else
|
||||||
|
echo -n "Installing plexupdate into '$FULL_PATH'... "
|
||||||
|
git clone "$ORIGIN_REPO" "$FULL_PATH" &> /dev/null || abort "install failed, cannot continue"
|
||||||
|
echo "done"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
configure_plexupdate() {
|
||||||
|
|
||||||
|
[ -f "$CONFIGFILE" ] && source "$CONFIGFILE"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Do you want to install the latest PlexPass releases? (requires PlexPass username and password) "
|
||||||
|
# The answer to this question and the value of PUBLIC are basically inverted
|
||||||
|
if [ "$PUBLIC" == "yes" ]; then
|
||||||
|
default=N
|
||||||
|
fi
|
||||||
|
if yesno $default; then
|
||||||
|
PUBLIC=no
|
||||||
|
while true; do
|
||||||
|
read -e -p "PlexPass Email Address: " -i "$EMAIL" EMAIL
|
||||||
|
if [ -z "${EMAIL}" ] || [[ "$EMAIL" == *"@"* ]] && [[ "$EMAIL" != *"@"*"."* ]]; then
|
||||||
|
echo "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
|
||||||
|
echo "Please provide a password"
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
# don't forget to erase old settings if they changed their answer
|
||||||
|
EMAIL=
|
||||||
|
PASS=
|
||||||
|
PUBLIC=yes
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Would you like to automatically install the latest release when it is downloaded? "
|
||||||
|
|
||||||
|
if yesno "$AUTOINSTALL"; then
|
||||||
|
AUTOINSTALL=yes
|
||||||
|
|
||||||
|
[ -z "$DISTRO" ] && check_distro
|
||||||
|
if [ "$DISTRO" == "redhat" ]; then
|
||||||
|
AUTOSTART=yes
|
||||||
|
else
|
||||||
|
AUTOSTART=
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "When using the auto-install option, would you like to check if the server is in use before upgrading? "
|
||||||
|
#We can't tell if they previously selected no or if this is their first run, so we have to assume Yes
|
||||||
|
if yesno; then
|
||||||
|
if [ -z "$PLEXSERVER" ]; then
|
||||||
|
PLEXSERVER="127.0.0.1"
|
||||||
|
fi
|
||||||
|
while true; do
|
||||||
|
read -e -p "Plex Server IP/DNS name: " -i "$PLEXSERVER" PLEXSERVER
|
||||||
|
if ! ping -c 1 -w 1 "$PLEXSERVER" &>/dev/null ; then
|
||||||
|
echo -n "Server $PLEXSERVER isn't responding, are you sure you entered it correctly? "
|
||||||
|
if yesno N; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -z "$PLEXPORT" ]; then
|
||||||
|
PLEXPORT=32400
|
||||||
|
fi
|
||||||
|
while true; do
|
||||||
|
read -e -p "Plex Server Port: " -i "$PLEXPORT" PLEXPORT
|
||||||
|
if ! [[ "$PLEXPORT" =~ ^[1-9][0-9]*$ ]]; then
|
||||||
|
echo "Port $PLEXPORT isn't valid, please try again"
|
||||||
|
PLEXPORT=32400
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
PLEXSERVER=
|
||||||
|
PLEXPORT=
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
AUTOINSTALL=no
|
||||||
|
PLEXSERVER=
|
||||||
|
PLEXPORT=
|
||||||
|
fi
|
||||||
|
|
||||||
|
save_config "AUTOINSTALL AUTODELETE DOWNLOADDIR EMAIL PASS FORCE FORCEALL PUBLIC AUTOSTART AUTOUPDATE PLEXSERVER PLEXPORT CHECKUPDATE" "$CONFIGFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
configure_cron() {
|
||||||
|
if [ ! -d "$(dirname "$CRONWRAPPER")" ]; then
|
||||||
|
echo "It seems like you don't have a supported cron job setup, please see README.md for more details."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -f "$CONFIGCRON" ] && source "$CONFIGCRON"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Would you like to set up automatic daily updates for Plex? "
|
||||||
|
if yesno $CRON; then
|
||||||
|
if [ $(sudo find -L "${FULL_PATH}" -perm /002 -or -not -uid 0 -or -not -gid 0 | wc -l) -ne 0 ]; then
|
||||||
|
echo
|
||||||
|
echo "WARNING: For security reasons, plexupdate needs to be installed as root in order to run automatically. In order to finish setting up automatic updates, we will change the ownership of '${FULL_PATH}' to root:root."
|
||||||
|
echo -n "Do you wish to continue? "
|
||||||
|
yesno || return 1
|
||||||
|
echo
|
||||||
|
echo -n "Changing ownership of '${FULL_PATH}'... "
|
||||||
|
sudo chown -R root:root "${FULL_PATH}" || abort "Unable to change ownership, cannot continue"
|
||||||
|
sudo chmod -R o-w "${FULL_PATH}" || abort "Unable to change permissions, cannot continue"
|
||||||
|
echo "done"
|
||||||
|
fi
|
||||||
|
|
||||||
|
CONF="$CONFIGFILE"
|
||||||
|
SCRIPT="${FULL_PATH}/plexupdate.sh"
|
||||||
|
LOGGING=${LOGGING:-false}
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Do you want to log the daily update runs to syslog so you can examine the output later? "
|
||||||
|
if yesno $LOGGING; then
|
||||||
|
LOGGING=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
save_config "CONF SCRIPT LOGGING" "/etc/plexupdate.cron.conf"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Installing daily cron job... "
|
||||||
|
sudo ln -sf "${FULL_PATH}/extras/cronwrapper" "$CRONWRAPPER"
|
||||||
|
echo "done"
|
||||||
|
elif [ -f "$CRONWRAPPER" -o -f "$CONFIGCRON" ]; then
|
||||||
|
echo
|
||||||
|
echo -n "Cleaning up old cron configuration... "
|
||||||
|
if [ -f "$CRONWRAPPER" ]; then
|
||||||
|
sudo rm "$CRONWRAPPER" || echo "Failed to remove old cron script, please check '$CRONWRAPPER'"
|
||||||
|
fi
|
||||||
|
if [ -f "$CONFIGCRON" ]; then
|
||||||
|
sudo rm "$CONFIGCRON" || echo "Failed to remove old cron configuration, please check '$CONFIGCRON'"
|
||||||
|
fi
|
||||||
|
echo done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
save_config() {
|
||||||
|
CONFIGTEMP=$(mktemp /tmp/plexupdate.XXX)
|
||||||
|
for VAR in $1; do
|
||||||
|
if [ ! -z "${!VAR}" ]; then
|
||||||
|
echo "${VAR}='${!VAR}'" >> $CONFIGTEMP
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Writing configuration file '$2'... "
|
||||||
|
|
||||||
|
# make sure that new file is owned by root instead of owner of CONFIGTEMP
|
||||||
|
sudo tee "$2" > /dev/null < "$CONFIGTEMP"
|
||||||
|
rm "$CONFIGTEMP"
|
||||||
|
|
||||||
|
echo "done"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $EUID -ne 0 ]; then
|
||||||
|
echo
|
||||||
|
echo "This script needs to install files in system locations and will ask for sudo/root permissions now"
|
||||||
|
sudo -v || abort "Root permissions are required for setup, cannot continue"
|
||||||
|
elif [ ! -z "$SUDO_USER" ]; then
|
||||||
|
echo
|
||||||
|
abort "This script will ask for sudo as necessary, but you should not run it as sudo. Please try again."
|
||||||
|
fi
|
||||||
|
|
||||||
|
for req in wget git; do
|
||||||
|
if ! hash $req 2>/dev/null; then
|
||||||
|
install $req
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -f ~/.plexupdate ]; then
|
||||||
|
echo
|
||||||
|
echo -n "Existing configuration found in ~/.plexupdate, would you like to import these settings? "
|
||||||
|
if yesno; then
|
||||||
|
echo "Backing up old configuration as ~/.plexupdate.old. All new settings should be modified through this script, or by editing ${CONFIGFILE} directly. Please see README.md for more details."
|
||||||
|
source ~/.plexupdate
|
||||||
|
mv ~/.plexupdate ~/.plexupdate.old
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$(dirname "$0")/../plexupdate.sh" -a -d "$(dirname "$0")/../.git" ]; then
|
||||||
|
FULL_PATH="$(readlink -f "$(dirname "$0")/../")"
|
||||||
|
echo
|
||||||
|
echo "Found plexupdate.sh in '$FULL_PATH', using that as your install path"
|
||||||
|
else
|
||||||
|
install_plexupdate
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
configure_plexupdate
|
||||||
|
configure_cron
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Configuration complete. Would you like to run plexupdate with these settings now? "
|
||||||
|
if yesno; then
|
||||||
|
if wget --show-progress -V &> /dev/null; then
|
||||||
|
PROGRESS_OPT="-P"
|
||||||
|
fi
|
||||||
|
if [ "$AUTOINSTALL" == "yes" ]; then
|
||||||
|
sudo "$FULL_PATH/plexupdate.sh" $PROGRESS_OPT --config "$CONFIGFILE"
|
||||||
|
else
|
||||||
|
"$FULL_PATH/plexupdate.sh" $PROGRESS_OPT --config "$CONFIGFILE"
|
||||||
|
fi
|
||||||
|
fi
|
821
plexupdate.sh
821
plexupdate.sh
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue