e6e11fe9f774586c87f5f721df5290133d5471f1
3 #==BEGIN Define script parameters==
4 declare -Ag appRollCall
# Associative array for storing app status
5 declare -Ag fileRollCall
# Associative array for storing file status
6 declare -Ag dirRollCall
# Associative array for storing dir status
8 #===BEGIN Declare local script functions===
10 # Desc: If arg is a command, save result in assoc array 'appRollCall'
11 # Usage: checkapp arg1 arg2 arg3 ...
12 # Input: global assoc. array 'appRollCall'
13 # Output: adds/updates key(value) to global assoc array 'appRollCall'
15 #echo "DEBUG:$(date +%S.%N)..Starting checkapp function."
16 #echo "DEBUG:args: $@"
17 #echo "DEBUG:returnState:$returnState"
21 #echo "DEBUG:processing arg:$arg"
22 if command -v $arg 1>/dev
/null
2>&1; then # Check if arg is a valid command
23 appRollCall
[$arg]="true";
24 #echo "DEBUG:appRollCall[$arg]:"${appRollCall[$arg]}
25 if ! [ "$returnState" = "false" ]; then returnState
="true"; fi
27 appRollCall
[$arg]="false"; returnState
="false";
31 #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done
32 #echo "DEBUG:evaluating returnstate. returnState:"$returnState
34 #===Determine function return code===
35 if [ "$returnState" = "true" ]; then
36 #echo "DEBUG:checkapp returns true for $arg";
39 #echo "DEBUG:checkapp returns false for $arg";
42 } # Check that app exists
44 # Desc: If arg is a file path, save result in assoc array 'fileRollCall'
45 # Usage: checkfile arg1 arg2 arg3 ...
46 # Input: global assoc. array 'fileRollCall'
47 # Output: adds/updates key(value) to global assoc array 'fileRollCall';
48 # Output: returns 0 if app found, 1 otherwise
53 #echo "DEBUG:processing arg:$arg"
54 if [ -f "$arg" ]; then
55 fileRollCall
["$arg"]="true";
56 #echo "DEBUG:fileRollCall[\"$arg\"]:"${fileRollCall["$arg"]}
57 if ! [ "$returnState" = "false" ]; then returnState
="true"; fi
59 fileRollCall
["$arg"]="false"; returnState
="false";
63 #for key in "${!fileRollCall[@]}"; do echo "DEBUG:fileRollCall key [$key] is:${fileRollCall[$key]}"; done
64 #echo "DEBUG:evaluating returnstate. returnState:"$returnState
66 #===Determine function return code===
67 if [ "$returnState" = "true" ]; then
68 #echo "DEBUG:checkapp returns true for $arg";
71 #echo "DEBUG:checkapp returns false for $arg";
74 } # Check that file exists
76 # Desc: If arg is a dir path, save result in assoc array 'dirRollCall'
77 # Usage: checkdir arg1 arg2 arg3 ...
78 # Input: global assoc. array 'dirRollCall'
79 # Output: adds/updates key(value) to global assoc array 'dirRollCall';
80 # Output: returns 0 if app found, 1 otherwise
85 #echo "DEBUG:processing arg:$arg"
86 if [ -d "$arg" ]; then
87 dirRollCall
["$arg"]="true";
88 #echo "DEBUG:dirRollCall[\"$arg\"]:"${dirRollCall["$arg"]}
89 if ! [ "$returnState" = "false" ]; then returnState
="true"; fi
91 dirRollCall
["$arg"]="false"; returnState
="false";
95 #for key in "${!dirRollCall[@]}"; do echo "DEBUG:dirRollCall key [$key] is:${dirRollCall[$key]}"; done
96 #echo "DEBUG:evaluating returnstate. returnState:"$returnState
98 #===Determine function return code===
99 if [ "$returnState" = "true" ]; then
100 #echo "DEBUG:checkapp returns true for $arg";
103 #echo "DEBUG:checkapp returns false for $arg";
106 } # Check that dir exists
107 #===END Declare local script functions===
108 #==END Define script parameters==
110 #==BEGIN sample code==
111 if checkapp
cat; then echo "cat found."; fi
112 if checkapp gpg
; then echo "gpg found."; fi
113 if checkapp emaaaacs
; then echo "emaaaacs found."; fi
116 #==BEGIN Display errors==
117 #===BEGIN Display Missing Apps===
118 missingApps
="Missing apps :"
119 #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done
120 for key
in "${!appRollCall[@]}"; do
121 value
="${appRollCall[$key]}"
122 if [ "$value" = "false" ]; then
123 #echo "DEBUG:Missing apps: $key => $value";
124 missingApps
="$missingApps""$key "
128 if [ "$appMissing" = "true" ]; then # Only indicate if an app is missing.
129 echo "$missingApps" 1>&2;
131 #===END Display Missing Apps===
133 #===BEGIN Display Missing Files===
134 missingFiles
="Missing files:"
135 #for key in "${!fileRollCall[@]}"; do echo "DEBUG:$key => ${fileRollCall[$key]}"; done
136 for key
in "${!fileRollCall[@]}"; do
137 value
="${fileRollCall[$key]}"
138 if [ "$value" = "false" ]; then
139 #echo "DEBUG:Missing files: $key => $value";
140 missingFiles
="$missingFiles""$key "
144 if [ "$fileMissing" = "true" ]; then # Only indicate if an app is missing.
145 echo "$missingFiles" 1>&2;
147 #===END Display Missing Files===
149 #===BEGIN Display Missing Directories===
150 missingDirs
="Missing dirs:"
151 #for key in "${!dirRollCall[@]}"; do echo "DEBUG:$key => ${dirRollCall[$key]}"; done
152 for key
in "${!dirRollCall[@]}"; do
153 value
="${dirRollCall[$key]}"
154 if [ "$value" = "false" ]; then
155 #echo "DEBUG:Missing dirs: $key => $value";
156 missingDirs
="$missingDirs""$key "
160 if [ "$dirMissing" = "true" ]; then # Only indicate if an dir is missing.
161 echo "$missingDirs" 1>&2;
163 #===END Display Missing Directories===
165 #===BEGIN Display Failed Functions===
166 if [ ${#failedFunctions} -gt 0 ]; then # Only indicate if an function failed.
167 echo "Failed functions:${failedFunctions[@]}" 1>&2;
169 #===END Display Failed Functions===
171 #==END Display errors==