X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/1092c1371aa542a04ac9240c1fc10649e6895ecf..aa6c5250cb316329f0a3f1874c6faa6e6880d530:/unitproc/bktemplate

diff --git a/unitproc/bktemplate b/unitproc/bktemplate
index df66f70..81cd17c 100755
--- a/unitproc/bktemplate
+++ b/unitproc/bktemplate
@@ -1,6 +1,5 @@
 #!/bin/bash
 
-# Date: 2020-06:19T22:12Z
 # Author: Steven Baltakatei Sandoval
 # Description: Template for bash scripts.
 # Note: Use hide-show-block function to aid readability. (ex: https://www.emacswiki.org/emacs/HideShow ).
@@ -16,15 +15,18 @@ SCRIPT_VERSION="bktemplate.sh 0.0.0" # Define version of script. Used by functio
 SCRIPT_TIME_SHORT="$(date +%Y%m%dT%H%M%S%z)" # Save current date & time in ISO-8601 format (YYYYmmddTHHMMSS+zzzz).
 SCRIPT_DATE_SHORT="$(date +%Y%m%d)"          # Save current date in ISO-8601 format.
 
+#==BEGIN Define script parameters
+declare -Ag appRollCall # Associative array for storing app status (function checkapp())
+declare -Ag fileRollCall # Associative array for storing file status (function checkfile())
+#==END Define script parameters
+
 #== Function Definitions ==
 
-# Yell, Die, Try Three-Fingered Claw technique
-# Ref/Attrib: https://stackoverflow.com/a/25515370
-yell() { echo "$0: $*" >&2; }
+
+yell() { echo "$0: $*" >&2; } # Yell, Die, Try Three-Fingered Claw technique; # Ref/Attrib: https://stackoverflow.com/a/25515370
 die() { yell "$*"; exit 111; }
 try() { "$@" || die "cannot $*"; }
 
-
 echoerr() {
     # Usage: echo [ arguments ]
     # Description: Prints provided arguments to stderr.
@@ -340,6 +342,73 @@ updateTimeConstants() {
     vbm "DEBUG:updateTimeConstants function ended."
     return 0; # Function finished.
 } # Update time constants
+checkapp() {
+    # Desc: If arg is a command, save result in assoc array 'appRollCall'
+    # Usage: checkapp arg1 arg2 arg3 ...
+    # Input: global assoc. array 'appRollCall'
+    # Output: adds/updates key(value) to global assoc array 'appRollCall'
+    local returnState    
+    #echo "DEBUG:$(date +%S.%N)..Starting checkapp function."
+    #echo "DEBUG:args: $@"
+    #echo "DEBUG:returnState:$returnState"
+
+    #===Process Args===
+    for arg in "$@"; do
+	#echo "DEBUG:processing arg:$arg"
+	if command -v $arg 1>/dev/null 2>&1; then # Check if arg is a valid command
+	    appRollCall[$arg]="true";
+	    #echo "DEBUG:appRollCall[$arg]:"${appRollCall[$arg]}
+	    if ! [ "$returnState" = "false" ]; then returnState="true"; fi
+	else
+	    appRollCall[$arg]="false"; returnState="false";
+	fi
+    done
+    
+    #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done
+    #echo "DEBUG:evaluating returnstate. returnState:"$returnState
+
+    #===Determine function return code===
+    if [ "$returnState" = "true" ]; then
+	#echo "DEBUG:checkapp returns true for $arg";
+	return 0;
+    else
+	#echo "DEBUG:checkapp returns false for $arg";
+	return 1;
+    fi
+} # Check that app exists
+checkfile() {
+    # Desc: If arg is a file path, save result in assoc array 'fileRollCall'
+    # Usage: checkfile arg1 arg2 arg3 ...
+    # Input: global assoc. array 'fileRollCall'
+    # Output: adds/updates key(value) to global assoc array 'fileRollCall';
+    # Output: returns 0 if app found, 1 otherwise
+    local returnState
+
+    #===Process Args===
+    for arg in "$@"; do
+	#echo "DEBUG:processing arg:$arg"
+	if [ -f "$arg" ]; then
+	    fileRollCall["$arg"]="true";
+	    #echo "DEBUG:fileRollCall[\"$arg\"]:"${fileRollCall["$arg"]}
+	    if ! [ "$returnState" = "false" ]; then returnState="true"; fi
+	else
+	    fileRollCall["$arg"]="false"; returnState="false";
+	fi
+    done
+
+    #for key in "${!fileRollCall[@]}"; do echo "DEBUG:fileRollCall key [$key] is:${fileRollCall[$key]}"; done
+    #echo "DEBUG:evaluating returnstate. returnState:"$returnState
+    
+    #===Determine function return code===
+    if [ "$returnState" = "true" ]; then
+	#echo "DEBUG:checkapp returns true for $arg";
+	return 0;
+    else
+	#echo "DEBUG:checkapp returns false for $arg";
+	return 1;
+    fi
+} # Check that file exists
+
 
 #== Main Program Definition ==
 main() {