chore(user/bk-naut-hide):Add version number
[BK-2020-03.git] / user / bkots
index fa9b7da2525451a7145d59182b0097169a575b1e..f829ce6887faa10990c0bdb50d86c56dd199c7df 100644 (file)
@@ -5,6 +5,12 @@ declare -Ag appRollCall # Associative array for storing app status
 declare -Ag fileRollCall # Associative array for storing file status
 declare -Ag dirRollCall # Associative array for storing dir status
 declare -ag arrayPosArgs # Associative array for processArgs() function
+declare -g ots_delay; ots_delay=1 # minimum time in seconds between ots operations
+declare -ag calendars;
+calendars+=("https://finney.calendar.eternitywall.com");
+calendars+=("https://btc.calendar.catallaxy.com");
+calendars+=("https://alice.btc.calendar.opentimestamps.org");
+calendars+=("https://bob.btc.calendar.opentimestamps.org");
 
 # Declare functions
 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
@@ -193,7 +199,7 @@ showVersion() {
     vbm "DEBUG:showVersion function called."
 
     cat <<'EOF'
-bkots 0.0.1
+bkots 0.0.8
 Copyright (C) 2022 Steven Baltakatei Sandoval
 License GPLv3: GNU GPL version 3
 This is free software; you are free to change and redistribute it.
@@ -359,8 +365,8 @@ main() {
     #             [2] How to find files containing newlines in their names https://stackoverflow.com/a/21727028
     local -a file_list file_list_pruned;
     local -a files_to_verify files_to_upgrade files_to_stamp
-    local -a files_to_verify_pruned files_to_upgrade_pruned files_to_stamp_pruned 
-
+    local -a files_to_verify_pruned files_to_upgrade_pruned files_to_stamp_pruned
+    
     # Process args
     processArgs "$@";
     
@@ -469,6 +475,12 @@ main() {
             yell "INFO :Skipping file ending in tilde:$item";
             continue; # skip to next item
         fi;
+
+        ## Ignore files that end in '.ots.bak'.
+        if [[ $item =~ '.ots.bak'$ ]]; then
+            yell "INFO :Skipping file ending in '.ots.bak':item:$item";
+            continue; # skip to next item
+        fi;
         
         ## Add item to file_list_pruned
         file_list_pruned+=("$item");
@@ -611,11 +623,15 @@ main() {
         fi;
         vbm "DEBUG:Attempting to upgrade proof file:path_prf:$path_prf";
         if [[ ! $option_dry_run == "true" ]]; then
-            ots upgrade "$path_prf";
+            ### Try upgrade with known calendars in random order
+            while read -r url; do
+                vbm "DEBUG:Upgrading with calendar:url:$url";
+                ots -l "$url" --no-default-whitelist upgrade "$path_prf" && break;
+            done < <(printf "%s\n" "${calendars[@]}" | shuf);
         else
             yell "DEBUG:DRY RUN:Not running:\"ots upgrade $path_prf\"";
         fi;
-        
+        #sleep "$ots_delay";
     done;
 
     ## Verify files
@@ -629,11 +645,15 @@ main() {
         vbm "DEBUG:Attempting to verify source file:path_src:$path_src";
         vbm "DEBUG:    against proof file:          path_prf:$path_prf";
         if [[ ! $option_dry_run == "true" ]]; then
-            ots verify -f "$path_src" "$path_prf";
+            ### Try verify with known calendars in random order
+            while read -r url; do
+                vbm "DEBUG:Verifying with calendar:url:$url";
+                ots -l "$url" --no-default-whitelist verify -f "$path_src" "$path_prf" && break;
+            done < <(printf "%s\n" "${calendars[@]}" | shuf);
         else
             yell "DEBUG:DRY RUN:Not running:\"ots verify -f $path_src $path_prf\"";
         fi;
-        
+        #sleep "$ots_delay";
     done;
     
     ## Stamp files
@@ -645,11 +665,11 @@ main() {
         fi;
         vbm "DEBUG:Attempting to stamp source file:path_src:$path_src";
         if [[ ! $option_dry_run == "true" ]]; then
-            ots stamp "$item";
+            ots stamp "$path_src";
         else
-            yell "DEBUG:DRY RUN:Not running:\"ots stamp $item\"";
+            yell "DEBUG:DRY RUN:Not running:\"ots stamp $path_src\"";
         fi;
-        
+        sleep "$ots_delay";
     done;
 
 }; # main program