bin/validate_artifactory_git_lfs

#!/bin/bash
# vim:ts=2:sw=2:tw=79
 
set -euo pipefail
shopt -s extglob
shopt -s nocasematch
 
main () {
  local lfs_url="$(git config --get lfs.url)"
 
  if [[ "$lfs_url" =~ ://([^:/].+):([0-9]+)/(.*) ]] ; then
    local ssh_host="${BASH_REMATCH[1]}"
    local ssh_port="${BASH_REMATCH[2]}"
    local repo_path="${BASH_REMATCH[3]}"
    local results="$(ssh -p "$ssh_port" "$ssh_host" \
      git-lfs-authenticate "$repo_path" download 0abcd)"
 
    if [[ "$results" = '{"header":{"Authorization":"Bearer'* ]] ; then
      >&2 echo "$results"
      echo "Authentication with Artifactory was successful."
      return 0
 
    else
      >&2 echo "Authentication with Artifactory was not successful."
      return 1
    fi
 
  else
    >&2 echo "Unable to parse lfs.url string '$lfs_url'."
    return 2
  fi
}
 
main "$@"