From fb0a30814daadaaad48c5360fd39493264d7e644 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 23 May 2021 10:44:51 +0200 Subject: [PATCH] fix: validate user input for amount of Klipper instances to install --- scripts/install_klipper.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index ae3c713..9146a85 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -18,19 +18,19 @@ klipper_setup_dialog(){ check_klipper_cfg_path ### ask for amount of instances to create - while true; do + INSTANCE_COUNT="" + while [[ ! ($INSTANCE_COUNT =~ ^[1-9]+$) ]]; do + echo + read -p "${cyan}###### Amount of Klipper instances to set up:${default} " INSTANCE_COUNT + if [[ ! ($INSTANCE_COUNT =~ ^[1-9]+$) ]]; then + warn_msg "Invalid Input!" && echo + else echo - read -p "${cyan}###### How many Klipper instances do you want to set up?:${default} " INSTANCE_COUNT - echo - if [ $INSTANCE_COUNT == 1 ]; then - read -p "${cyan}###### Create $INSTANCE_COUNT single instance? (Y/n):${default} " yn - else - read -p "${cyan}###### Create $INSTANCE_COUNT instances? (Y/n):${default} " yn - fi + read -p "${cyan}###### Install $INSTANCE_COUNT instance(s)? (Y/n):${default} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" - status_msg "Creating $INSTANCE_COUNT Klipper instances ..." + status_msg "Installing $INSTANCE_COUNT Klipper instance(s) ..." klipper_setup break;; N|n|No|no) @@ -41,7 +41,8 @@ klipper_setup_dialog(){ *) print_unkown_cmd print_msg && clear_msg;; - esac + esac + fi done }