From b1159b5b9f815292d140abf9f8511e78a2e68e20 Mon Sep 17 00:00:00 2001 From: hugmouse Date: Wed, 19 Jun 2024 18:04:28 +0200 Subject: [PATCH] fix: also add explicit check for wget or curl, exit if neither of them present --- yabs.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/yabs.sh b/yabs.sh index 87c7ad1..955c079 100644 --- a/yabs.sh +++ b/yabs.sh @@ -20,13 +20,18 @@ echo -e '# '$YABS_VERSION' #' echo -e '# https://github.com/masonr/yet-another-bench-script #' echo -e '# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #' +# Define a function to check command availability before using it +function check_command() { + command -v "$1" &>/dev/null +} + # Check for required commands and add warnings if not available REQUIRED_COMMANDS=("locale" "uname" "getconf" "awk" "sed" "grep" "cut" "shuf" "timeout" "date" "trap" "df" "free" "systemd-detect-virt") echo -e "\nChecking available commands" echo -e "---------------------------------" for cmd in "${REQUIRED_COMMANDS[@]}"; do - if command -v "$cmd" &>/dev/null; then + if check_command "$cmd"; then printf "%-20s : \xE2\x9C\x94 installed\n" "$cmd" else printf "%-20s : \xE2\x9D\x8C not installed\n" "$cmd" @@ -34,10 +39,18 @@ for cmd in "${REQUIRED_COMMANDS[@]}"; do fi done -# Define a function to check command availability before using it -function check_command() { - command -v "$1" &>/dev/null -} +# Check for curl/wget +if check_command "curl"; then + LOCAL_CURL=true + echo -e "curl : \xE2\x9C\x94 installed" +elif check_command "wget"; then + echo -e "wget : \xE2\x9C\x94 installed" +else + echo -e "curl/wget : \xE2\x9D\x8C not installed" + echo -e "\nError: Neither 'curl' nor 'wget' command found. Please install one of those to continue." + echo -e + exit 1 +fi echo -e if check_command "date"; then