2 # Finds and verifies signatures of git repositories in specified dir 
   3 # Usage: bk-find-git-verify [DIR] 
   4 # Depends: GNU parallel 20210822, sort (GNU coreutils) 8.32 
   8 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr 
   9 die
() { yell 
"$*"; exit 111; } # same as yell() but non-zero exit status 
  10 try
() { "$@" || die 
"cannot $*"; } # runs args as command, reports args if command fails 
  12     # usage: git_verify_ops arg1 
  13     # input: arg1   git work tree root dir 
  15     # depends: yell(), die(), try() 
  19     ## End function early if arg1 not a dir 
  20     if [[ ! $# -eq 1 ]]; then yell 
"ERROR:Incorrect number of args:$#"; return 1; fi; 
  21     if [[ ! -d "$1" ]]; then yell 
"ERROR:Not a dir:$1"; return 1; fi; 
  22     ## TODO: Check if "$1" is git repo 
  23     yell 
"DEBUG:Running git_verify_ops on dir:$1"; 
  25     # Change work dir to target repo 
  26     pushd "$1" 1>/dev
/random 
2>&1; 
  28     # Get list of git tags 
  29     list_tags
="$(git tag --list)"; 
  31     # Verify git commit signatures 
  32     yell 
"Starting git log of dir:$1"; 
  33     git log 
--show-signature 1>/dev
/random 
2>&1; 
  34     yell 
"Ending git log of dir:$1"; 
  38         yell 
"DEBUG:Verifying tag:$tag"; 
  39         git verify-tag 
"$tag" 1>/dev
/random 
2>&1; 
  40     done < <(printf "%s" "$list_tags"); 
  42     # Return to original work dir 
  43     popd 1>/dev
/random 
2>&1; 
  47 }; # Verify signatures on git commits and tags 
  49     # depends: yell(), die(), try() 
  51     if [[ ! $# -eq 1 ]]; then die 
"FATAL:Incorrect arg count:$#"; fi; 
  52     if [[ ! -d "$1" ]]; then die 
"FATAL:Not a dir:$1"; fi; 
  54     # Get list of dirs containing '.git' directory 
  55     dir_list
="$(find "$1" -type d -name ".git
" 2>/dev/random | parallel dirname '{}' | sort -u)"; 
  57     # Perform git verify operations on each directory 
  58     printf "%s" "$dir_list" | parallel git_verify_ops 
'{}';     
  62 export -f yell die try git_verify_ops