Use defaults for installer

Implemented needed changes for #189
This commit is contained in:
Doug Fultz 2017-11-13 22:00:51 -05:00 committed by GitHub
commit 09d513a671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,7 @@ CRONWRAPPER="/etc/cron.daily/plexupdate"
VERBOSE=yes #to be inherited by get-plex-token, do not save to config VERBOSE=yes #to be inherited by get-plex-token, do not save to config
# default options # default options
USEDEFAULTS=false
AUTOINSTALL=yes AUTOINSTALL=yes
AUTOUPDATE=yes AUTOUPDATE=yes
PUBLIC= PUBLIC=
@ -16,6 +17,19 @@ PUBLIC=
CONFIGVARS="AUTOINSTALL AUTODELETE DOWNLOADDIR TOKEN 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"
usage() {
echo "Usage: $(basename $0) [-h] [<long options>]"
echo ""
echo ""
echo " -h This help"
echo ""
echo " Long Argument Options:"
echo " --default Use defaults for all prompts"
echo " --help This help"
echo ""
exit 0
}
install() { install() {
echo "'$req' is required but not installed, attempting to install..." echo "'$req' is required but not installed, attempting to install..."
sleep 1 sleep 1
@ -75,7 +89,11 @@ yesno() {
fi fi
while true; do while true; do
if $USEDEFAULTS; then
echo "$prompt"
else
read -n 1 -p "$prompt" answer read -n 1 -p "$prompt" answer
fi
answer=${answer:-$default} answer=${answer:-$default}
answer="$(tr "[:lower:]" "[:upper:]" <<< "$answer")" answer="$(tr "[:lower:]" "[:upper:]" <<< "$answer")"
@ -193,9 +211,17 @@ configure_plexupdate() {
PLEXSERVER="127.0.0.1" PLEXSERVER="127.0.0.1"
fi fi
while true; do while true; do
read -e -p "Plex Server IP/DNS name: " -i "$PLEXSERVER" PLEXSERVER prompt="Plex Server IP/DNS name:"
if $USEDEFAULTS; then
echo "$prompt $PLEXSERVER"
else
read -e -p "$prompt " -i "$PLEXSERVER" PLEXSERVER
fi
if ! ping -c 1 -w 1 "$PLEXSERVER" &>/dev/null ; then if ! ping -c 1 -w 1 "$PLEXSERVER" &>/dev/null ; then
echo -n "Server $PLEXSERVER isn't responding, are you sure you entered it correctly? " echo -n "Server $PLEXSERVER isn't responding, are you sure you entered it correctly? "
if $USEDEFAULTS; then
abort
fi
if yesno N; then if yesno N; then
break break
fi fi
@ -207,7 +233,12 @@ configure_plexupdate() {
PLEXPORT=32400 PLEXPORT=32400
fi fi
while true; do while true; do
read -e -p "Plex Server Port: " -i "$PLEXPORT" PLEXPORT prompt="Plex Server Port:"
if $USEDEFAULTS; then
echo "$prompt $PLEXPORT"
else
read -e -p "$prompt " -i "$PLEXPORT" PLEXPORT
fi
if ! [[ "$PLEXPORT" =~ ^[1-9][0-9]*$ ]]; then if ! [[ "$PLEXPORT" =~ ^[1-9][0-9]*$ ]]; then
echo "Port $PLEXPORT isn't valid, please try again" echo "Port $PLEXPORT isn't valid, please try again"
PLEXPORT=32400 PLEXPORT=32400
@ -323,6 +354,19 @@ for req in wget git; do
fi fi
done done
while true;
do
case "$1" in
(-h) usage;;
(--default) USEDEFAULTS=true;;
(--help) usage;;
(-*) error "Unrecognized option $1"; usage; exit 1;;
(*) break;;
esac
shift
done
if [ -f ~/.plexupdate ]; then if [ -f ~/.plexupdate ]; then
echo echo
echo -n "Existing configuration found in ~/.plexupdate, would you like to import these settings? " echo -n "Existing configuration found in ~/.plexupdate, would you like to import these settings? "