From 05164ad4bc76f565088dd4f743646a8571528dd8 Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Mon, 29 Jul 2024 11:24:34 +0200 Subject: [PATCH 1/5] Add a check for the bash shell to archdetect --- init/eessi_archdetect.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/init/eessi_archdetect.sh b/init/eessi_archdetect.sh index ddfed1bfae..afa6c0b387 100755 --- a/init/eessi_archdetect.sh +++ b/init/eessi_archdetect.sh @@ -1,4 +1,26 @@ #!/usr/bin/env bash + +# Confirm the current shell is Bash >= 4 +check_bash() { + if [ -n "$BASH_VERSION" ]; then + # Extract the major version numbers + bash_version=$(echo "$BASH_VERSION" | grep -oP '^\d+\.\d+') + major_version=$(echo "$bash_version" | cut -d. -f1) + + # Check if the major version is 4 or higher + if [ "$major_version" -ge 4 ]; then + return 0 + else + echo "Error: This script must be run with Bash > 4, you have $BASH_VERSION." >&2 + exit 1 + fi + else + echo "Error: This script must be run with Bash." >&2 + exit 1 + fi +} +check_bash + VERSION="1.1.0" # default log level: only emit warnings or errors From 6f43f1349daecd474805828af255abec4d83f2a7 Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Mon, 29 Jul 2024 11:35:22 +0200 Subject: [PATCH 2/5] List compatibility --- init/eessi_archdetect.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/init/eessi_archdetect.sh b/init/eessi_archdetect.sh index afa6c0b387..ed6a1f8c51 100755 --- a/init/eessi_archdetect.sh +++ b/init/eessi_archdetect.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Confirm the current shell is Bash >= 4 +# (works for sh, bash, dash, zsh, ksh, but not fish, tcsh, elvish) check_bash() { if [ -n "$BASH_VERSION" ]; then # Extract the major version numbers From 47c0a34173e8431f22794905e8c6addd81a3210c Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Mon, 29 Jul 2024 11:38:33 +0200 Subject: [PATCH 3/5] Don't declare a function for bash check --- init/eessi_archdetect.sh | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/init/eessi_archdetect.sh b/init/eessi_archdetect.sh index ed6a1f8c51..0e83a45d2f 100755 --- a/init/eessi_archdetect.sh +++ b/init/eessi_archdetect.sh @@ -2,25 +2,22 @@ # Confirm the current shell is Bash >= 4 # (works for sh, bash, dash, zsh, ksh, but not fish, tcsh, elvish) -check_bash() { - if [ -n "$BASH_VERSION" ]; then - # Extract the major version numbers - bash_version=$(echo "$BASH_VERSION" | grep -oP '^\d+\.\d+') - major_version=$(echo "$bash_version" | cut -d. -f1) - - # Check if the major version is 4 or higher - if [ "$major_version" -ge 4 ]; then - return 0 - else - echo "Error: This script must be run with Bash > 4, you have $BASH_VERSION." >&2 - exit 1 - fi +if [ -n "$BASH_VERSION" ]; then + # Extract the major version numbers + bash_version=$(echo "$BASH_VERSION" | grep -oP '^\d+\.\d+') + major_version=$(echo "$bash_version" | cut -d. -f1) + + # Check if the major version is 4 or higher + if [ "$major_version" -ge 4 ]; then + return 0 else - echo "Error: This script must be run with Bash." >&2 + echo "Error: This script must be run with Bash > 4, you have $BASH_VERSION." >&2 exit 1 fi -} -check_bash +else + echo "Error: This script must be run with Bash." >&2 + exit 1 +fi VERSION="1.1.0" From 0750f5f4f0753dcb08362a4ed9dae90faf4b157c Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Mon, 29 Jul 2024 11:41:34 +0200 Subject: [PATCH 4/5] Don't use return values --- init/eessi_archdetect.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/init/eessi_archdetect.sh b/init/eessi_archdetect.sh index 0e83a45d2f..001683f50a 100755 --- a/init/eessi_archdetect.sh +++ b/init/eessi_archdetect.sh @@ -8,9 +8,7 @@ if [ -n "$BASH_VERSION" ]; then major_version=$(echo "$bash_version" | cut -d. -f1) # Check if the major version is 4 or higher - if [ "$major_version" -ge 4 ]; then - return 0 - else + if [ "$major_version" -lt 4 ]; then echo "Error: This script must be run with Bash > 4, you have $BASH_VERSION." >&2 exit 1 fi From bbe101b0dda05658d2f0692f8d65132fa7ab6900 Mon Sep 17 00:00:00 2001 From: ocaisa Date: Tue, 30 Jul 2024 13:16:15 +0200 Subject: [PATCH 5/5] Update eessi_archdetect.sh --- init/eessi_archdetect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/eessi_archdetect.sh b/init/eessi_archdetect.sh index 001683f50a..ad6dce6f9a 100755 --- a/init/eessi_archdetect.sh +++ b/init/eessi_archdetect.sh @@ -9,7 +9,7 @@ if [ -n "$BASH_VERSION" ]; then # Check if the major version is 4 or higher if [ "$major_version" -lt 4 ]; then - echo "Error: This script must be run with Bash > 4, you have $BASH_VERSION." >&2 + echo "Error: This script must be run with Bash >= 4, you have $BASH_VERSION." >&2 exit 1 fi else