X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/2928a8e40d1950022451aad8fa94c668febad98b..d7ffba91c60ad9ffc96fe6176117a0d8543d02cf:/unitproc/bktemp-checkAppFileDir diff --git a/unitproc/bktemp-checkAppFileDir b/unitproc/bktemp-checkAppFileDir index d5a620b..94afbd8 100644 --- a/unitproc/bktemp-checkAppFileDir +++ b/unitproc/bktemp-checkAppFileDir @@ -38,7 +38,7 @@ checkapp() { checkfile() { # Desc: If arg is a file path, save result in assoc array 'fileRollCall' # Usage: checkfile arg1 arg2 arg3 ... - # Version: 0.1.1 + # Version: 0.1.2 # Input: global assoc. array 'fileRollCall' # Output: adds/updates key(value) to global assoc array 'fileRollCall'; # Output: returns 0 if app found, 1 otherwise @@ -50,6 +50,8 @@ checkfile() { if [ -f "$arg" ]; then fileRollCall["$arg"]="true"; if ! [ "$returnState" = "false" ]; then returnState="true"; fi; + elif [ -z "$arg" ]; then + fileRollCall["(no name)"]="false"; returnState="false"; else fileRollCall["$arg"]="false"; returnState="false"; fi; @@ -65,16 +67,18 @@ checkfile() { checkdir() { # Desc: If arg is a dir path, save result in assoc array 'dirRollCall' # Usage: checkdir arg1 arg2 arg3 ... - # Version 0.1.1 + # Version 0.1.2 # Input: global assoc. array 'dirRollCall' # Output: adds/updates key(value) to global assoc array 'dirRollCall'; - # Output: returns 0 if app found, 1 otherwise + # Output: returns 0 if all args are dirs; 1 otherwise # Depends: Bash 5.0.3 local returnState #===Process Args=== for arg in "$@"; do - if [ -d "$arg" ]; then + if [ -z "$arg" ]; then + dirRollCall["(Unspecified Dirname(s))"]="false"; returnState="false"; + elif [ -d "$arg" ]; then dirRollCall["$arg"]="true"; if ! [ "$returnState" = "false" ]; then returnState="true"; fi else @@ -92,13 +96,14 @@ checkdir() { displayMissing() { # Desc: Displays missing apps, files, and dirs # Usage: displayMissing - # Version 0.1.1 + # Version 1.0.0 # Input: associative arrays: appRollCall, fileRollCall, dirRollCall # Output: stderr: messages indicating missing apps, file, or dirs + # Output: returns exit code 0 if nothing missing; 1 otherwise # Depends: bash 5, checkAppFileDir() local missingApps value appMissing missingFiles fileMissing local missingDirs dirMissing - + #==BEGIN Display errors== #===BEGIN Display Missing Apps=== missingApps="Missing apps :"; @@ -152,6 +157,13 @@ displayMissing() { #===END Display Missing Directories=== #==END Display errors== + #==BEGIN Determine function return code=== + if [ "$appMissing" == "true" ] || [ "$fileMissing" == "true" ] || [ "$dirMissing" == "true" ]; then + return 1; + else + return 0; + fi + #==END Determine function return code=== } # Display missing apps, files, dirs #===END Declare local script functions=== @@ -160,9 +172,18 @@ displayMissing() { #==BEGIN sample code== if checkapp cat; then echo "cat found."; fi; if checkapp gpg; then echo "gpg found."; fi; +if displayMissing 1>/dev/null 2>&1; then + echo "Nothing missing so far..."; +fi; + if checkapp emaaaacs; then echo "emaaaacs found."; fi; sleep 1; -displayMissing; +if ! displayMissing 1>/dev/null 2>&1; then + echo "Something is missing!"; + displayMissing; +fi; +sleep 1; +myFile=""; if ! checkfile "$myFile"; then echo "An empty argument provided:$myFile"; displayMissing; fi; #==END sample code== # Author: Steven Baltaktei Sandoval