From 17983da5a95d53d2be69537e3816438d114c3d5b Mon Sep 17 00:00:00 2001 From: Peter Mikus Date: Wed, 31 Jul 2019 13:42:54 +0000 Subject: Add: Prerequisites checker Change-Id: Ida54722ee5c73a0b3e0a8e22692795daf5bb09f3 Signed-off-by: Peter Mikus --- resources/libraries/bash/function/common.sh | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'resources/libraries/bash/function') diff --git a/resources/libraries/bash/function/common.sh b/resources/libraries/bash/function/common.sh index f7a7a004df..751d994c09 100644 --- a/resources/libraries/bash/function/common.sh +++ b/resources/libraries/bash/function/common.sh @@ -167,6 +167,21 @@ function check_download_dir () { } +function check_prerequisites () { + + # Fail if prerequisites are not met. + # + # Functions called: + # - installed - Check if application is installed/present in system. + # - die - Print to stderr and exit. + + set -exuo pipefail + + if ! installed sshpass; then + die "Please install sshpass before continue!" + fi +} + function cleanup_topo () { # Variables read: @@ -520,6 +535,24 @@ function get_test_tag_string () { } +function installed () { + + # Check if the given utility is installed. Fail if not installed. + # + # Duplicate of common.sh function, as this file is also used standalone. + # + # Arguments: + # - ${1} - Utility to check. + # Returns: + # - 0 - If command is installed. + # - 1 - If command is not installed. + + set -exuo pipefail + + command -v "${1}" +} + + function reserve_and_cleanup_testbed () { # Reserve physical testbed, perform cleanup, register trap to unreserve. -- cgit 1.2.3-korg