#!/usr/bin/env bash set -euo pipefail # This will be set to 1 if we instruct the user to manually verify signatures, # when they have GPG but don't have the public key of the signer. Would be super # confusing to tell the user to use files that we've cleaned up. DO_CLEANUP=0 # shellcheck disable=SC2015 color_title=$(tput setaf 7 && tput bold || true) color_dim=$(tput setaf 8 || true) color_good=$(tput setaf 2 || true) color_bad=$(tput setaf 1 || true) color_warn=$(tput setaf 3 || true) color_reset=$(tput sgr0 || true) repo=https://repo.maven.apache.org/maven2 usage() { cat <&2 '%s\n' "${color_dim}> ${command[*]}${color_reset}" eval "${command[@]}" } fetch() { url="$1"; shift target="$1"; shift execute_and_log curl -fL -o "'$target'" "'$url'" } fetch_latest_version() { local artifact_group="$1"; shift local artifact_id="$1"; shift local url="${repo}/${artifact_group_with_slashes}/${artifact_id}/maven-metadata.xml" printf $(curl -sSL $url | sed -n '//s/.*\([^<]*\)<\/version>.*/\1/p'|tail -1) } artifact_part() { local index="$1"; shift local artifact="$1"; shift local parts IFS=':' read -ra parts <<< "$artifact" if [[ "${#parts[@]}" -lt $((index + 1)) ]]; then printf '' else printf '%s' "${parts[$index]}" fi } verify_version_number() { if [[ ! "$1" =~ ^[[:digit:]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then cat </dev/null 2>&1; then execute_and_log "md5sum --check <<< \"\$(cat $filename.md5) $filename\"" printf '%s\n' "${color_good}Checksum for ${filename} passes verification${color_reset}" else printf '%s\n' "${color_warn}md5sum not found on path, skipping checksum verification${color_reset}" fi } verify_signature() { local url="$1"; shift local filename="$1"; shift printf '\n%s\n' "${color_title}Verifying GPG signature of $filename...${color_reset}" local gpg_key='D401AB61' if command -v gpg >/dev/null 2>&1; then fetch "$url.asc" "$filename.asc" if gpg --list-keys "$gpg_key" >/dev/null 2>&1; then execute_and_log gpg --verify "$filename.asc" "$filename" printf '%s\n' "${color_good}GPG signature for ${filename} passes verification${color_reset}" else cat <