From: Steven Baltakatei Sandoval Date: Tue, 20 Sep 2022 23:29:28 +0000 (+0000) Subject: feat(user/bksum):Add wait option for timestamps X-Git-Tag: 0.5.1~2 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/07b20692dcdd8c69f7ee1e074a24deefee010d89?ds=sidebyside;hp=--cc feat(user/bksum):Add wait option for timestamps - Note: Equivalent to adding "--wait" to an `ots` command. - feat(unitproc/bktemp-count_jobs):Assign version number to count_jobs() function. --- 07b20692dcdd8c69f7ee1e074a24deefee010d89 diff --git a/unitproc/bktemp-count_jobs b/unitproc/bktemp-count_jobs index cf26234..9bde32d 100644 --- a/unitproc/bktemp-count_jobs +++ b/unitproc/bktemp-count_jobs @@ -9,6 +9,14 @@ yell() { echo "$0: $*" >&2; } # print script path and all args to stderr die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status try() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails count_jobs() { + # Desc: Count and return total number of jobs + # Usage: count_jobs + # Input: None. + # Output: stdout integer number of jobs + # Depends: Bash 5.1.16 + # Example: while [[$(count_jobs) -gt 0]]; do echo "Working..."; sleep 1; done; + # Version: 0.0.1 + local job_count; job_count="$(jobs -r | wc -l | tr -d ' ' )"; #yell "DEBUG:job_count:$job_count"; diff --git a/user/bksum b/user/bksum index ebf1f14..cb99cad 100755 --- a/user/bksum +++ b/user/bksum @@ -5,7 +5,7 @@ # arg(s): file paths (IFS delimited) # Output: file containing sha256 hashes and file paths # Depends: bash v5.1.16, date (GNU Coreutils 8.32), gpg v2.2.27, ots v0.7.0 -# Version: 0.0.2 +# Version: 0.1.0 declare -Ag appRollCall # Associative array for storing app status declare -Ag fileRollCall # Associative array for storing file status @@ -65,6 +65,11 @@ showUsage() { -t, --timestamp Timestamp with OpenTimestamps the checksum file (and GnuPG signature if -s/--sign specified). + -T, --timestamp-wait + Same as '-t/--timestamp' except that + OpenTimestamps will run as a background process + until a calendar server returns a completed + timestamp. -- Indicate end of options. @@ -272,6 +277,8 @@ processArgs() { # pathDirOut1 Path to output directory. # pathFileOut1 Path to output file. # opFileOut1_overwrite Indicates whether file pathFileOut1 should be overwritten (ex: "true", "false"). + # opTs Indicates timestamp mode + # opTsWait Indicates timestamp mode with wait option # arrPosArgs Array of remaining positional argments # Depends: # yell() Displays messages to stderr. @@ -319,7 +326,10 @@ processArgs() { -s | --sign) # sign with gpg opSign="true"; vbm "DEBUG:Signing mode enabled.";; -t | --timestamp) # timestamp with ots - opTimestamp="true"; vbm "DEBUG:Timestamp mode enabled.";; + opTs="true"; vbm "DEBUG:Timestamp mode enabled.";; + -T | --timestamp-wait) # timestamp with ots with wait option + opTs="true"; vbm "DEBUG:Timestamp mode enabled."; + opTsWait="true"; vbm "DEBUG:Timestamp wait mode enabled.";; --) # End of all options. See [2]. shift; for arg in "$@"; do @@ -410,11 +420,26 @@ checkDepends() { checkapp date sha256sum; if [[ $opSign == "true" ]]; then checkapp gpg; fi; - if [[ $opTimestamp == "true" ]]; then checkapp ots; fi; + if [[ $opTs == "true" ]]; then checkapp ots; fi; # Return failure is displayMissing() reports apps missing. if ! displayMissing; then return 1; else return 0; fi; }; # Check dependencies +count_jobs() { + # Desc: Count and return total number of jobs + # Usage: count_jobs + # Input: None. + # Output: stdout integer number of jobs + # Depends: Bash 5.1.16 + # Example: while [[$(count_jobs) -gt 0]]; do echo "Working..."; sleep 1; done; + # Version: 0.0.1 + + local job_count; + job_count="$(jobs -r | wc -l | tr -d ' ' )"; + #yell "DEBUG:job_count:$job_count"; + if [[ -z $job_count ]]; then job_count="0"; fi; + echo "$job_count"; +}; # Return number of background jobs main() { # Input: pathFileOut1 option-specified output file path # appRollCall assoc-array for checkapp(), displayMissing() @@ -458,17 +483,43 @@ main() { # Do optional work ## Sign checksum file. if [[ $opSign == "true" ]]; then - try gpg --detach-sign --armor --output "$pathSigOut" "$pathSumOut"; + yell "STATUS:Signing checksum file..."; + try gpg --detach-sign --armor --output "$pathSigOut" "$pathSumOut" && yell "STATUS:Checksum created."; fi; ## Timestamp checksum file. - if [[ $opTimestamp == "true" ]]; then - try ots s "$pathSumOut"; fi; - + if [[ $opTs == "true" ]]; then + yell "STATUS:Timestamping checksum file..."; + if [[ $opTsWait != "true" ]]; then + try ots s "$pathSumOut" & + elif [[ $opTsWait == "true" ]]; then + yell "NOTICE:Waiting for calendar server response in background. (This may take 8 to 24 hours)..."; + yell "ADVICE:Do not close or suspend this terminal."; + try ots --wait s "$pathSumOut" & + fi; + fi; ## Timestamp checksum signature file. - if [[ $opTimestamp == "true" && $opSign == "true" ]]; then - try ots s "$pathSigOut"; + if [[ $opTs == "true" && $opSign == "true" ]]; then + yell "STATUS:Timestamping signature file..."; + if [[ $opTsWait != "true" ]]; then + try ots s "$pathSigOut" && yell "STATUS:Timestamp of checksum signature file created."; + elif [[ $opTsWait == "true" ]]; then + yell "NOTICE:Waiting for calendar server response in background. (This may take 8 to 24 hours)..."; + yell "ADVICE:Do not close or suspend this terminal."; + try ots --wait s "$pathSigOut" & + fi; fi; + ## Wait until background jobs (if any) completed + for (( n = 1; "$(count_jobs)" > 0; n++ )); do + if ! [[ $((n % 60)) -eq 0 ]]; then + printf "."; + else + printf ".%05ds passed.\n" "$SECONDS"; + fi; + sleep 60; + done; + + yell "Done."; return 0; }; # main program