- for item in "${files_to_upgrade_pruned[@]}"; do
- wait_for_jobslot && {
- path_prf="$(cut -d $'\n' -f1 < <(echo "$item"))";
- if [[ -z "$path_prf" ]]; then
- yell "ERROR:blank upgrade item encountered. Skipping:item:$item";
- return 1; # would have been `continue` were it not in a subshell
- fi;
- vbm "DEBUG:Attempting to upgrade proof file:path_prf:$path_prf";
- if [[ ! $option_dry_run == "true" ]]; then
- ### Try upgrade with known calendars in random order
- while read -r url; do
- vbm "DEBUG:Upgrading with calendar:url:$url";
-
- #### assemble command
- local -a cmd_temp;
- cmd_temp=("ots");
- if [[ "$opVerbose" = "true" ]]; then cmd_temp+=("-v"); fi;
- cmd_temp+=("-l" "$url" "--no-default-whitelist");
- cmd_temp+=("upgrade" "$path_prf");
- if [[ "$opVerbose" = "true" ]]; then declare -p cmd_temp; fi;
-
- #### execute command
- "${cmd_temp[@]}";
- unset cmd_temp;
- break;
- #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;
- } &
- done;
-
- ## Assemble and execute verify file commands
- for item in "${files_to_verify_pruned[@]}"; do
- wait_for_jobslot && {
- path_src="$(cut -d $'\n' -f1 < <(echo "$item"))";
- path_prf="$(cut -d $'\n' -f2 < <(echo "$item"))";
- if [[ -z "$path_src" ]] || [[ -z "$path_prf" ]]; then
- yell "ERROR:blank verify item encountered. Skipping:item:$item";
- return 1; # would have been `continue` were it not in a subshell
- fi;
- 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
- ### Try verify with known calendars in random order
- while read -r url; do
- vbm "DEBUG:Verifying with calendar:url:$url";
-
- #### assemble command
- local -a cmd_temp;
- cmd_temp=("ots");
- if [[ "$opVerbose" = "true" ]]; then cmd_temp+=("-v"); fi;
- cmd_temp+=("-l" "$url" "--no-default-whitelist");
- cmd_temp+=("verify" "-f" "$path_src" "$path_prf");
- if [[ "$opVerbose" = "true" ]]; then declare -p cmd_temp; fi;
-
- #### execute command
- "${cmd_temp[@]}";
- unset cmd_temp;
- break;
- #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;
- } &
- done;
+ if [[ ${#files_to_upgrade_pruned[@]} -gt 0 ]]; then
+ if [[ $option_dry_run == "true" ]]; then
+ yell "DEBUG:DRY RUN:Not running:\"ots upgrade\"";
+ else
+ ### Pick random calendar
+ function get_calurl() {
+ # Desc: Returns random calendar url
+ # Input: string OTS_CALS newline-delimited list of calendars
+ # Output: stdout single calendar url
+ printf "%s" "$OTS_CALS" | shuf -n1;
+ }; # print random calendar url to stdout
+ export -f get_calurl;
+
+ ### Perform upgrade command in xargs batches
+ printf '%s\0' "${files_to_upgrade_pruned[@]}" \
+ | shuf -z \
+ | xargs -0 -r -n "$max_batch_size" -P "$max_job_count" bash -c 'ots --no-default-whitelist -l "$(get_calurl)" upgrade "$@";' _ ;
+ fi;
+ fi;