Add: Prerequisites checker
[csit.git] / resources / libraries / bash / function / common.sh
index f7a7a00..751d994 100644 (file)
@@ -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.