From e1794dfbf6a857781d083492ce13861a908a720e Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 28 Apr 2023 14:48:32 +0200 Subject: [PATCH] Update template --- templates/skeleton.sh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/templates/skeleton.sh b/templates/skeleton.sh index 67bae11..0095eea 100755 --- a/templates/skeleton.sh +++ b/templates/skeleton.sh @@ -100,14 +100,39 @@ define_vars() { # {{{ } # }}} +is_command_available() { # {{{ + + local_command_available_cmd="${1}" + debug_prefix="${2:-}" + + ## Return False by default + return_command_available="1" + + if [ "$(command -v ${local_command_available_cmd})" ]; then + debug_message "${debug_prefix}is_command_available − \ +${RED}${local_command_available_cmd}${COLOR_DEBUG} seems present on this host." + return_command_available="0" + else + debug_message "${debug_prefix}is_command_available − \ +${RED}${local_command_available_cmd}${COLOR_DEBUG} is not available on this host." + return_command_available="1" + fi + + unset local_command_available_cmd + unset debug_prefix + + return "${return_command_available}" +} +# }}} + main() { # {{{ debug_message "--- MAIN BEGIN" - ## If script should not be executed right now {{{ - ### Exit - is_script_ok \ - && exit 0 + ## If a command is missing {{{ + ### Exit with error message + is_command_available "test_me" "| " \ + || error_message "No test_me command available. Please install test_me package with your package manager." 01 ## }}} ## Define all vars