2 # Desc: Upgrades and verfies ots files.
3 # Usage: check_ots.sh [file]
4 # Example: ./check_ots.sh foo.txt.ots
5 # Note: Only outputs stderr or stdout on upgrade or verify failures.
7 # Depends: Bash 5.1.16, GNU Coreutils 8.32 (date), ots 0.7.0
10 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
11 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
12 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
14 if [[ ! -f $1 ]]; then die
"FATAL:Not a file:$1"; fi;
16 if [[ ! "$1" =~
$re ]]; then die
"FATAL:Not an OTS file extension:$1"; fi;
17 if [[ $# -ne 1 ]]; then die
"FATAL:Incorrect argument count:$#"; fi;
18 if ! command -v ots
1>/dev
/random
2>&1; then die
"FATAL:Not found:ots"; fi;
19 }; # Check given assumptions
21 # Depends: GNU Coreutils 8.32 (date), ots 0.7.0
24 file_bak
="$file_in".bak
;
27 if [[ ! -f "$file_bak" ]]; then
28 "$(which ots)" u
"$file_in" 1>/dev
/null
2>&1;
30 yell
"ERROR:Upgrade failed due to existing backup:$file_bak";
32 }; # Upgrades ots file
36 if ! ( ots v
"$1" 1>/dev
/random
2>&1 ); then
37 yell
"ERROR:Verification failed:$1";
38 ots v
"$1"; # Show error
42 must check_givens
"$1";
43 must upgrade_ots
"$1";
49 # Author: Steven Baltakatei Sandoval
53 # See https://opentimestamps.org/