diff options
author | Peter Mikus <pmikus@cisco.com> | 2019-07-31 13:42:54 +0000 |
---|---|---|
committer | Vratko Polak <vrpolak@cisco.com> | 2019-07-31 14:48:15 +0000 |
commit | 17983da5a95d53d2be69537e3816438d114c3d5b (patch) | |
tree | b1cc5c378009f3479c635bcc3eeb87d6bb54b548 /resources/libraries/bash/function | |
parent | 18ddfb237072adfa7daaf64de769d5f05e98be1d (diff) |
Add: Prerequisites checker
Change-Id: Ida54722ee5c73a0b3e0a8e22692795daf5bb09f3
Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/bash/function')
-rw-r--r-- | resources/libraries/bash/function/common.sh | 33 |
1 files changed, 33 insertions, 0 deletions
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. |