Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use defaults for installer #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions extras/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CRONWRAPPER="/etc/cron.daily/plexupdate"
VERBOSE=yes #to be inherited by get-plex-token, do not save to config

# default options
USEDEFAULTS=false
AUTOINSTALL=yes
AUTOUPDATE=yes
PUBLIC=
Expand All @@ -16,6 +17,19 @@ PUBLIC=
CONFIGVARS="AUTOINSTALL AUTODELETE DOWNLOADDIR TOKEN FORCE FORCEALL PUBLIC AUTOSTART AUTOUPDATE PLEXSERVER PLEXPORT CHECKUPDATE NOTIFY"
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() {
echo "'$req' is required but not installed, attempting to install..."
sleep 1
Expand Down Expand Up @@ -75,7 +89,11 @@ yesno() {
fi

while true; do
read -n 1 -p "$prompt" answer
if $USEDEFAULTS; then
echo "$prompt"
else
read -n 1 -p "$prompt" answer
fi
answer=${answer:-$default}
answer="$(tr "[:lower:]" "[:upper:]" <<< "$answer")"

Expand Down Expand Up @@ -193,9 +211,17 @@ configure_plexupdate() {
PLEXSERVER="127.0.0.1"
fi
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
echo -n "Server $PLEXSERVER isn't responding, are you sure you entered it correctly? "
if $USEDEFAULTS; then
abort
fi
if yesno N; then
break
fi
Expand All @@ -207,7 +233,12 @@ configure_plexupdate() {
PLEXPORT=32400
fi
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
echo "Port $PLEXPORT isn't valid, please try again"
PLEXPORT=32400
Expand Down Expand Up @@ -323,6 +354,19 @@ for req in wget git; do
fi
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
echo
echo -n "Existing configuration found in ~/.plexupdate, would you like to import these settings? "
Expand Down