From: Steven Baltakatei Sandoval Date: Sat, 11 Jul 2020 05:00:08 +0000 (+0000) Subject: debug(bklog):Format DEBUG messages to align better X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/commitdiff_plain/fcefae4cb5df370a237319fd549ad185fa31ed83?hp=21363b806b9f1e8270be701f7f1929be47ed690e debug(bklog):Format DEBUG messages to align better --- diff --git a/exec/bklog b/exec/bklog index 6493015..6e166f1 100644 --- a/exec/bklog +++ b/exec/bklog @@ -11,7 +11,7 @@ dirTmpDefault="/dev/shm"; # Default parent of working directory # Script Metadata scriptName="bklog"; # Define basename of script file. -scriptVersion="0.1.13"; # Define version of script. +scriptVersion="0.1.14"; # Define version of script. scriptURL="https://gitlab.com/baltakatei/ninfacyzga-01"; # Define wesite hosting this script. scriptTimeStart="$(date +%Y%m%dT%H%M%S.%N)"; # YYYYmmddTHHMMSS.NNNNNNNNN scriptHostname=$(hostname); # Save hostname of system running this script. @@ -43,22 +43,22 @@ try() { "$@" || die "cannot $*"; } #o processArguments() { while [ ! $# -eq 0 ]; do # While number of arguments ($#) is not (!) equal to (-eq) zero (0). case "$1" in - -v | --verbose) optionVerbose="true"; vbm "DEBUG:Verbose mode enabled.";; # Enable verbose mode. + -v | --verbose) optionVerbose="true"; vbm "DEBUG :Verbose mode enabled.";; # Enable verbose mode. -h | --help) showUsage; exit 1;; # Display usage. --version) showVersion; exit 1;; # Show version - -o | --output) if [ -d "$2" ]; then dirOut="$2"; vbm "DEBUG:dirOut:$dirOut"; shift; fi ;; # Define output directory. - -e | --encrypt) optionEncrypt="true"; vbm "DEBUG:Encrypted output mode enabled.";; # Enable encryption + -o | --output) if [ -d "$2" ]; then dirOut="$2"; vbm "DEBUG :dirOut:$dirOut"; shift; fi ;; # Define output directory. + -e | --encrypt) optionEncrypt="true"; vbm "DEBUG :Encrypted output mode enabled.";; # Enable encryption -r | --recipient) optionRecipients="true"; argRecPubKeys+=("$2"); vbm "STATUS:pubkey added:""$2"; shift;; # Add recipients - -c | --compress) optionCompress="true"; vbm "DEBUG:Compressed output mode enabled.";; # Enable compression + -c | --compress) optionCompress="true"; vbm "DEBUG :Compressed output mode enabled.";; # Enable compression -z | --time-zone) try setTimeZoneEV "$2"; shift;; # Set timestamp timezone -t | --temp-dir) optionTmpDir="true" && argTempDirPriority="$2"; shift;; # Set time zone -R | --recipient-dir) optionRecipients="true"; optionRecDir="true" && argRecDir="$2"; shift;; # Add recipient watch dir -b | --buffer-ttl) optionCustomBufferTTL="true" && argCustomBufferTTL="$2"; shift;; # Set custom buffer period (default: 300 seconds) -B | --script-ttl) optionCustomScriptTTL_TE="true" && argCustomScriptTTL_TE="$2"; shift;; # Set custom script TTL (default: "day") -p | --process-string) optionProcString="true" && argProcStrings+=("$2") && argProcFileExts+=("$3") && vbm "STATUS:file extension \"$2\" for output of processing string added:\"$3\""; shift; shift;; - -l | --label) optionLabel="true" && argLabel="$2"; vbm "DEBUG:Custom label received:$argLabel"; shift;; - -w | --store-raw) optionStoreRaw="true" && argRawFileExt="$2"; vbm "DEBUG:Raw stdin file extension received:$argRawFileExt"; shift;; - -W | --no-store-raw) optionNoStoreRaw="true"; vbm "DEBUG:Option selected to not store raw stdin data."; shift;; + -l | --label) optionLabel="true" && argLabel="$2"; vbm "DEBUG :Custom label received:$argLabel"; shift;; + -w | --store-raw) optionStoreRaw="true" && argRawFileExt="$2"; vbm "DEBUG :Raw stdin file extension received:$argRawFileExt"; shift;; + -W | --no-store-raw) optionNoStoreRaw="true"; vbm "DEBUG :Option selected to not store raw stdin data."; shift;; *) yell "ERROR: Unrecognized argument: $1"; yell "STATUS:All arguments:$*"; exit 1;; # Handle unrecognized options. esac shift @@ -66,7 +66,7 @@ processArguments() { } # Argument Processing vbm() { # Description: Prints verbose message ("vbm") to stderr if optionVerbose is set to "true". - # Usage: vbm "DEBUG:verbose message here" + # Usage: vbm "DEBUG :verbose message here" # Version 0.1.2 # Input: arg1: string # vars: optionVerbose @@ -174,11 +174,11 @@ displayMissing() { #==BEGIN Display errors== #===BEGIN Display Missing Apps=== missingApps="Missing apps :"; - #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done + #for key in "${!appRollCall[@]}"; do echo "DEBUG :$key => ${appRollCall[$key]}"; done for key in "${!appRollCall[@]}"; do value="${appRollCall[$key]}"; if [ "$value" = "false" ]; then - #echo "DEBUG:Missing apps: $key => $value"; + #echo "DEBUG :Missing apps: $key => $value"; missingApps="$missingApps""$key "; appMissing="true"; fi; @@ -191,11 +191,11 @@ displayMissing() { #===BEGIN Display Missing Files=== missingFiles="Missing files:"; - #for key in "${!fileRollCall[@]}"; do echo "DEBUG:$key => ${fileRollCall[$key]}"; done + #for key in "${!fileRollCall[@]}"; do echo "DEBUG :$key => ${fileRollCall[$key]}"; done for key in "${!fileRollCall[@]}"; do value="${fileRollCall[$key]}"; if [ "$value" = "false" ]; then - #echo "DEBUG:Missing files: $key => $value"; + #echo "DEBUG :Missing files: $key => $value"; missingFiles="$missingFiles""$key "; fileMissing="true"; fi; @@ -208,11 +208,11 @@ displayMissing() { #===BEGIN Display Missing Directories=== missingDirs="Missing dirs:"; - #for key in "${!dirRollCall[@]}"; do echo "DEBUG:$key => ${dirRollCall[$key]}"; done + #for key in "${!dirRollCall[@]}"; do echo "DEBUG :$key => ${dirRollCall[$key]}"; done for key in "${!dirRollCall[@]}"; do value="${dirRollCall[$key]}"; if [ "$value" = "false" ]; then - #echo "DEBUG:Missing dirs: $key => $value"; + #echo "DEBUG :Missing dirs: $key => $value"; missingDirs="$missingDirs""$key "; dirMissing="true"; fi; @@ -245,7 +245,7 @@ appendFileTar(){ # Save function name fn="${FUNCNAME[0]}"; - #yell "DEBUG:STATUS:$fn:Started appendFileTar()." + #yell "DEBUG :STATUS:$fn:Started appendFileTar()." # Set file name if ! [ -z "$2" ]; then fileName="$2"; else yell "ERROR:$fn:Not enough arguments."; exit 1; fi @@ -264,7 +264,7 @@ appendFileTar(){ # Append to tar try tar --append --directory="$tmpDir" --file="$tarPath" "$fileName"; - #yell "DEBUG:STATUS:$fn:Finished appendFileTar()." + #yell "DEBUG :STATUS:$fn:Finished appendFileTar()." } # Append [processed] file to Tar archive checkAgePubkey() { # Desc: Checks if string is an age-compatible pubkey @@ -852,7 +852,7 @@ magicInitWorkingDir() { fi; fi; ## Set dir_tmp using dir_tmp_parent and nonce (scriptTimeStart) - dir_tmp="$dir_tmp_parent"/"$scriptTimeStart""..bkgpslog" && vbm "DEBUG:$fn:Set dir_tmp to:$dir_tmp"; # Note: removed at end of main(). + dir_tmp="$dir_tmp_parent"/"$scriptTimeStart""..bkgpslog" && vbm "DEBUG :$fn:Set dir_tmp to:$dir_tmp"; # Note: removed at end of main(). vbm "STATUS:$fn:Finished magicInitWorkingDir() function."; } # Sets working dir magicInitCheckTar() { @@ -898,7 +898,7 @@ magicParseCompressionArg() { else cmd_compress="tee /dev/null " && vbm "STATUS:$fn:cmd_compress:$cmd_compress"; cmd_compress_suffix="" && vbm "STATUS:$fn:cmd_compress_suffix:$cmd_compress_suffix"; - vbm "DEBUG:$fn:Compression not enabled."; + vbm "DEBUG :$fn:Compression not enabled."; fi; vbm "STATUS:$fn:Starting magicParseCompressionArg() function."; } # Form compression cmd string and filename suffix @@ -1053,20 +1053,20 @@ magicParseRecipientArgs() { if [[ "$optionEncrypt" = "true" ]] && [[ "$optionRecipients" = "true" ]]; then if checkapp age; then # Check that age is available. for pubkey in "${argRecPubKeys[@]}"; do # Validate recipient pubkey strings by forming test message - vbm "DEBUG:$fn:Testing pubkey string:$pubkey"; + vbm "DEBUG :$fn:Testing pubkey string:$pubkey"; if checkAgePubkey "$pubkey" && \ ( validateInput "$pubkey" "ssh_pubkey" || validateInput "$pubkey" "age_pubkey"); then #### Form age recipient string recipients="$recipients""-r '$pubkey' "; vbm "STATUS:$fn:Added pubkey for forming age recipient string:""$pubkey"; - vbm "DEBUG:$fn:recipients:""$recipients"; + vbm "DEBUG :$fn:recipients:""$recipients"; #### Add validated pubkey to recPubKeysValid array - recPubKeysValid+=("$pubkey") && vbm "DEBUG:$fn:recPubkeysValid:pubkey added:$pubkey"; + recPubKeysValid+=("$pubkey") && vbm "DEBUG :$fn:recPubkeysValid:pubkey added:$pubkey"; else yell "ERROR:$fn:Exit code ""$?"". Invalid recipient pubkey string. Exiting."; exit 1; fi; done - vbm "DEBUG:$fn:Finished processing argRecPubKeys array"; + vbm "DEBUG :$fn:Finished processing argRecPubKeys array"; vbm "STATUS:$fn:Array of validated pubkeys:${recPubKeysValid[*]}"; recPubKeysValidStatic=("${recPubKeysValid[@]}"); # Save static image of pubkeys validated by this function @@ -1079,7 +1079,7 @@ magicParseRecipientArgs() { else cmd_encrypt="tee /dev/null " && vbm "STATUS:$fn:cmd_encrypt:$cmd_encrypt"; cmd_encrypt_suffix="" && vbm "STATUS:$fn:cmd_encrypt_suffix:$cmd_encrypt_suffix"; - vbm "DEBUG:$fn:Encryption not enabled." + vbm "DEBUG :$fn:Encryption not enabled." fi; # Catch case if '-e' is set but '-r' or '-R' is not if [[ "$optionEncrypt" = "true" ]] && [[ ! "$optionRecipients" = "true" ]]; then @@ -1234,9 +1234,9 @@ magicProcessWriteBuffer() { # Determine file paths (time is start of buffer period) ## Calculate start time timeBufferStartLong="$(date --date="$bufferTTL seconds ago" --iso-8601=seconds)" && \ - vbm "DEBUG:$fn:timeBufferStartLong:$timeBufferStartLong"; + vbm "DEBUG :$fn:timeBufferStartLong:$timeBufferStartLong"; timeBufferStart="$(dateTimeShort "$timeBufferStartLong" )" && \ - vbm "DEBUG:$fn:timeBufferStart:$timeBufferStart"; # Note start time YYYYmmddTHHMMSS+zzzz (no separators) + vbm "DEBUG :$fn:timeBufferStart:$timeBufferStart"; # Note start time YYYYmmddTHHMMSS+zzzz (no separators) ## Set common basename fileoutBasename="$timeBufferStart""--""$bufferTTL_STR""..""$scriptHostname""$label" && \ vbm "STATUS:$fn:Set fileoutBasename to:$fileoutBasename"; @@ -1316,9 +1316,9 @@ main() { ## Set script lifespan (scriptTTL from scriptTTL_TE) magicSetScriptTTL "$scriptTTL_TE"; ## File name substring (ISO-8601 duration from bufferTTL) - bufferTTL_STR="$(timeDuration "$bufferTTL")" && vbm "DEBUG:$fn:bufferTTL_STR:$bufferTTL_STR"; + bufferTTL_STR="$(timeDuration "$bufferTTL")" && vbm "DEBUG :$fn:bufferTTL_STR:$bufferTTL_STR"; ## Init temp working dir - try mkdir "$dir_tmp" && vbm "DEBUG:$fn:Working dir created at dir_tmp:$dir_tmp"; + try mkdir "$dir_tmp" && vbm "DEBUG :$fn:Working dir created at dir_tmp:$dir_tmp"; ## Initialize output tar (set pathout_tar) magicInitCheckTar; @@ -1340,7 +1340,7 @@ main() { # Create dir_tmp if missing if ! [[ -d "$dir_tmp" ]]; then yell "ERROR:$fn:dir_tmp existence failure:$dir_tmp"; - try mkdir "$dir_tmp" && vbm "DEBUG:$fn:Working dir recreated dir_tmp:$dir_tmp"; fi + try mkdir "$dir_tmp" && vbm "DEBUG :$fn:Working dir recreated dir_tmp:$dir_tmp"; fi # Update encryption recipient array magicParseRecipientDir; # Update recPubKeysValid with argRecDir # Export buffer to asynchronous processing.