.plexupdate location improved

You can now specify a different file than ~/.plexupdate

It now also tries to handle sudo better in respect to the location
of this file.

This closes #38
This commit is contained in:
Henric Andersson 2016-07-16 14:12:18 -07:00
parent f3f24fc97e
commit 4837eded60
2 changed files with 52 additions and 5 deletions

View file

@ -28,7 +28,9 @@ Obviously you need to change these three so they match your account information.
## 3. advanced options
There are a few other options for the more enterprising user. Setting any of these to `yes` will enable the function.
You can point out a different file than ```.plexupdate``` by providing it as the first argument to the script. It HAS to be the FIRST argument, or it will be ignored.
There are also a few additional options for the more enterprising user. Setting any of these to `yes` will enable the function.
- AUTOUPDATE
Makes plexupdate.sh automatically update itself using git. Note! This will fail if git isn't available on the command line.

View file

@ -72,10 +72,51 @@ if [ $? -eq 127 ]; then
exit 1
fi
# Allow manual control of configfile
if [ ! "$1" = "" -a ! "${1:0:1}" = "-" ]; then
if [ -f "$1" ]; then
source "$1"
else
echo "ERROR: Cannot load configuration $1" >&2
exit 1
fi
else
# Load settings from config file if it exists
if [ -f ~/.plexupdate ]; then
# Also, respect SUDO_USER and try that first
if [ "${SUDO_USER}" != "" ]; then
# Make sure nothing bad comes from this (since we use eval)
ERROR=0
if [[ $SUDO_USER == *";"* ]]; then ERROR=1 ; # Allows more commands
elif [[ $SUDO_USER == *" "* ]]; then ERROR=1 ; # Space is not a good thing
elif [[ $SUDO_USER == *"&"* ]]; then ERROR=1 ; # Spinning off the command is bad
elif [[ $SUDO_USER == *"<"* ]]; then ERROR=1 ; # No redirection
elif [[ $SUDO_USER == *">"* ]]; then ERROR=1 ; # No redirection
elif [[ $SUDO_USER == *"|"* ]]; then ERROR=1 ; # No pipes
elif [[ $SUDO_USER == *"~"* ]]; then ERROR=1 ; # No tilde
fi
if [ ${ERROR} -gt 0 ]; then
echo "ERROR: SUDO_USER variable is COMPROMISED: \"${SUDO_USER}\"" >&2
exit 255
fi
# Try using original user's config
CONFIGDIR="$( eval cd ~${SUDO_USER} 2>/dev/null && pwd )"
if [ "${CONFIGDIR}" == "" ]; then
echo "WARNING: SUDO_USER \"${SUDO_USER}\" does not have a valid home directory, ignoring." >&2
fi
if [ "${CONFIGDIR}" != "" -a -f "${CONFIGDIR}/.plexupdate" ]; then
#echo "INFO: Using \"${SUDO_USER}\" configuration: ${CONFIGDIR}/.plexupdate"
source "${CONFIGDIR}/.plexupdate"
elif [ -f ~/.plexupdate ]; then
# Fallback for compatibility
source ~/.plexupdate
fi
elif [ -f ~/.plexupdate ]; then
# Fallback for compatibility
source ~/.plexupdate
fi
fi
if [ ! "${RELEASE}" = "" ]; then
echo "ERROR: RELEASE keyword is deprecated and should be removed from .plexupdate" >&2
@ -97,7 +138,11 @@ cronexit() {
}
usage() {
echo "Usage: $(basename $0) [-acfhkopqsSuU]"
echo "Usage: $(basename $0) [configfile] [-acfhkopqsSuU]"
echo ""
echo " configfile overrides the default ~/.plexupdate"
echo " If used, it must be the FIRST option or it will be ignored"
echo ""
echo " -a Auto install if download was successful (requires root)"
echo " -c Cron mode, only fatal errors return non-zero cronexit code"
echo " -d Auto delete after auto install"