From bc117c0ab527f672f735ae1f7c806940ce5c563f Mon Sep 17 00:00:00 2001 From: gobborg <81018718+gobborg@users.noreply.github.com> Date: Sat, 21 Oct 2023 05:01:15 +0000 Subject: [PATCH] =?UTF-8?q?Print=20abort()=20echo=20'Installation=20aborte?= =?UTF-8?q?d'=20to=20stdout.=20Allow=20\n=20(ENTER)=E2=80=A6=20(#109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Print abort() echo 'Installation aborted' to stdout. Allow \n (ENTER) to be the printed default: yes. * Actually handling the null response instead of galaxy brained putting a 'continue' as a placeholder in a conditional tree. --- install | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/install b/install index 32ee4aa..a9c9e0f 100755 --- a/install +++ b/install @@ -34,7 +34,7 @@ comfortable-swipe stop > /dev/null 2>&1 || true # shorthand to abort the installation function abort { - echo "Installation aborted" + echo "Installation aborted" >&2 exit 1 } @@ -67,14 +67,23 @@ function install_configuration_file { # ask user if we overwrite configuration echo "Old conf file found in $CONF_TARGET" >&2 read -r -p "Keep the old conf file? (default: yes) [Y/n] " response >&2 - if ! [[ "${response,,}" =~ ^(yes|y)$ ]]; then + + # If response is empty, consider it as 'yes' (default) + if [[ -z "$response" ]]; then + response="y" + fi + + if [[ "${response,,}" =~ ^(no|n)$ ]]; then # MAKE SURE they really want to overwrite read -r -p "Conf file will be overwritten! Are you sure? [Y/n] " response >&2 - if [[ "${response,,}" =~ ^(yes|y)$ ]]; then + if [[ -z "$response" ]]; then + response="y" + fi + if [[ "${response,,}" =~ ^(no|n)$ ]]; then + abort + else # They agreed... replace configuration cat "$CONF_SOURCE" > "$CONF_TARGET" - else - abort fi fi else