Added sanity checks

- Yes/No questions now require yes or no (or enter for default)
- Email is checked so it's an actual email address (well, close to anyway)
- Password cannot be blank
- Server address is ping:ed and if it fails, prompts user to confirm the choice
- Port is tested so it's an actual port (1 and up, all numeric)
- Cron option isn't run if the /etc/cron.daily exists (notifies user)
This commit is contained in:
Henric Andersson 2016-11-20 12:16:44 -08:00
commit 7de3c8d758

85
extras/installer.sh Normal file → Executable file
View file

@ -29,29 +29,31 @@ install() {
} }
yesno() { yesno() {
read -n 1 -p "[Y/n] " answer while true; do
read -n 1 -p "[Y/n] " answer
if [ "$answer" == "n" -o "$answer" == "N" ]; then if [ "$answer" == "n" -o "$answer" == "N" ]; then
echo echo
return 1 return 1
elif [ ! -z "$answer" ]; then elif [ -z "$answer" -o "$answer" == "y" -o "$answer" == "Y" ]; then
echo echo
fi return 0
fi
return 0 done
} }
noyes() { noyes() {
read -n 1 -p "[N/y] " answer while true; do
read -n 1 -p "[N/y] " answer
if [ "$answer" == "y" -o "$answer" == "Y" ]; then if [ "$answer" == "y" -o "$answer" == "Y" ]; then
echo echo
return 1 return 1
elif [ ! -z "$answer" ]; then elif [ -z "$answer" -o "$answer" == "n" -o "$answer" == "N" ]; then
echo echo
fi return 0
fi
return 0 done
} }
abort() { abort() {
@ -70,8 +72,22 @@ configure_plexupdate() {
echo -n "Do you want to install the latest PlexPass releases? " echo -n "Do you want to install the latest PlexPass releases? "
if yesno; then if yesno; then
PUBLIC= PUBLIC=
read -e -p "PlexPass Email Address: " -i "$EMAIL" EMAIL while true; do
read -e -p "PlexPass Password: " -i "$PASS" PASS read -e -p "PlexPass Email Address: " -i "$EMAIL" EMAIL
if [ -z "$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 else
EMAIL= EMAIL=
PASS= PASS=
@ -93,12 +109,29 @@ configure_plexupdate() {
if [ -z "$PLEXSERVER" ]; then if [ -z "$PLEXSERVER" ]; then
PLEXSERVER="127.0.0.1" PLEXSERVER="127.0.0.1"
fi fi
read -e -p "Plex Server IP/DNS name: " -i "$PLEXSERVER" PLEXSERVER 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 ! noyes; then
break
fi
else
break
fi
done
if [ -z "$PLEXPORT" ]; then if [ -z "$PLEXPORT" ]; then
PLEXPORT=32400 PLEXPORT=32400
fi fi
while true; do
read -e -p "Plex Server Port: " -i "$PLEXPORT" PLEXPORT 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 else
PLEXSERVER= PLEXSERVER=
PLEXPORT= PLEXPORT=
@ -224,4 +257,8 @@ else
fi fi
configure_plexupdate configure_plexupdate
configure_cron if [ -d "$(dirname "$CRONWRAPPER")" ]; then
configure_cron
else
echo "Seems like you don't have a supported cron job setup, please see README.md for more details."
fi