From 53881d768d915dc6f0d97890e7bd1c7592f56ef9 Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 25 Apr 2017 11:58:57 +0200 Subject: [PATCH] better parsing of user answers Change-Id: I29df9a8dc27d12e7438bee32a9111ae1ff7a41b7 Signed-off-by: tierno --- installers/install_osm.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/installers/install_osm.sh b/installers/install_osm.sh index f24f9383..f7397242 100755 --- a/installers/install_osm.sh +++ b/installers/install_osm.sh @@ -183,6 +183,19 @@ function install_lxd() { systemctl start lxd-bridge } +function ask_user(){ + # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive + # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed + # Return: true(0) if user type 'yes'; false (1) if user type 'no' + read -e -p "$1" USER_CONFIRMATION + while true ; do + [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0 + [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1 + [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0 + [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1 + read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION + done +} UNINSTALL="" DEVELOP="" @@ -284,9 +297,7 @@ OSM_JENKINS="$TEMPDIR/jenkins" #Installation starts here echo -e "\nInstalling OSM from refspec: $COMMIT_ID" if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then - read -e -p "The installation will take about 75-90 minutes. Continue (Y/n)?" USER_CONFIRMATION - [ -n "$USER_CONFIRMATION" ] && [ "$USER_CONFIRMATION" != "yes" ] && \ - [ "$USER_CONFIRMATION" != "y" ] && echo "Cancelled!" && exit 0 + ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1 fi echo -e "\nChecking required packages: wget, curl, tar" -- 2.25.1