3 # Desc: Outputs to stdout the current iso-8601 timestamp (minute accuracy)
4 # Usage: tick_minute.sh
5 # Example tick_minute.sh
7 #==BEGIN Define script parameters==
8 #===BEGIN Declare variables===
9 declare -Ag appRollCall
# Associative array for storing app status
10 declare -Ag fileRollCall
# Associative array for storing file status
11 declare -Ag dirRollCall
# Associative array for storing dir status
13 #===END Declare variables===
16 #===BEGIN Declare local script functions===
17 yell
() { echo "$0: $*" >&2; } # Yell, Die, Try Three-Fingered Claw technique; # Ref/Attrib: https://stackoverflow.com/a/25515370
18 die
() { yell
"$*"; exit 111; }
19 try
() { "$@" || die
"cannot $*"; }
21 # Desc: If arg is a command, save result in assoc array 'appRollCall'
22 # Usage: checkapp arg1 arg2 arg3 ...
24 # Input: global assoc. array 'appRollCall'
25 # Output: adds/updates key(value) to global assoc array 'appRollCall'
31 if command -v "$arg" 1>/dev
/null
2>&1; then # Check if arg is a valid command
32 appRollCall
[$arg]="true";
33 if ! [ "$returnState" = "false" ]; then returnState
="true"; fi;
35 appRollCall
[$arg]="false"; returnState
="false";
39 #===Determine function return code===
40 if [ "$returnState" = "true" ]; then
45 } # Check that app exists
47 # Desc: Displays missing apps, files, and dirs
48 # Usage: displayMissing
50 # Input: associative arrays: appRollCall, fileRollCall, dirRollCall
51 # Output: stderr: messages indicating missing apps, file, or dirs
52 # Depends: bash 5, checkAppFileDir()
53 local missingApps value appMissing missingFiles fileMissing
54 local missingDirs dirMissing
56 #==BEGIN Display errors==
57 #===BEGIN Display Missing Apps===
58 missingApps
="Missing apps :";
59 #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done
60 for key
in "${!appRollCall[@]}"; do
61 value
="${appRollCall[$key]}";
62 if [ "$value" = "false" ]; then
63 #echo "DEBUG:Missing apps: $key => $value";
64 missingApps
="$missingApps""$key ";
68 if [ "$appMissing" = "true" ]; then # Only indicate if an app is missing.
69 echo "$missingApps" 1>&2;
72 #===END Display Missing Apps===
74 #===BEGIN Display Missing Files===
75 missingFiles
="Missing files:";
76 #for key in "${!fileRollCall[@]}"; do echo "DEBUG:$key => ${fileRollCall[$key]}"; done
77 for key
in "${!fileRollCall[@]}"; do
78 value
="${fileRollCall[$key]}";
79 if [ "$value" = "false" ]; then
80 #echo "DEBUG:Missing files: $key => $value";
81 missingFiles
="$missingFiles""$key ";
85 if [ "$fileMissing" = "true" ]; then # Only indicate if an app is missing.
86 echo "$missingFiles" 1>&2;
89 #===END Display Missing Files===
91 #===BEGIN Display Missing Directories===
92 missingDirs
="Missing dirs:";
93 #for key in "${!dirRollCall[@]}"; do echo "DEBUG:$key => ${dirRollCall[$key]}"; done
94 for key
in "${!dirRollCall[@]}"; do
95 value
="${dirRollCall[$key]}";
96 if [ "$value" = "false" ]; then
97 #echo "DEBUG:Missing dirs: $key => $value";
98 missingDirs
="$missingDirs""$key ";
102 if [ "$dirMissing" = "true" ]; then # Only indicate if an dir is missing.
103 echo "$missingDirs" 1>&2;
106 #===END Display Missing Directories===
108 #==END Display errors==
109 } # Display missing apps, files, dirsw
112 # Input: var: arg1: path
113 # var: appRollCall checkapp() dependency
114 # var: exitFlag indicates to script if exit required
115 # Output: stdout: iso-8601 date string
119 ## Check argument count (must be 0)
120 if [[ $# -gt 0 ]]; then yell
"ERROR:Too many arguments:$#"; exitFlag
="true"; fi;
123 if ! checkapp
date echo; then yell
"ERROR:Missing App"; exitFlag
="true"; fi;
127 if [[ $exitFlag == "true" ]]; then exit 1; fi;
130 output
="$(date +%Y-%m-%dT%H:%M%z)"; #iso-8601 string (e.g. 2021-05-28T19:18+0000)
136 #===END Declare local script functions===
137 #==END Define script parameters==