Skip to content

Commit

Permalink
Adds validate_gradle_wrapper script
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzkocer committed Nov 16, 2022
1 parent f0507d1 commit c0616cf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bin/validate_gradle_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash -eu

CHECKSUM_URLS=$(curl -s https://services.gradle.org/versions/all | jq -r ".[].wrapperChecksumUrl? | select(.)")

function validate_checksum() {
wrapper_location="$1"
validated_with_checksum_from_url=""

wrapper_checksum=$(shasum --algorithm=256 "$wrapper_location")
# Remove the file location from the "wrapper_checksum" result
sha256_checksum_to_be_validated="${wrapper_checksum%% *}"

while IFS= read -r checksum_url; do
downloaded_checksum=$(curl -s --location "$checksum_url")
if [[ "$sha256_checksum_to_be_validated" == "$downloaded_checksum" ]]; then
validated_with_checksum_from_url="$checksum_url"
break;
fi
done <<< "$CHECKSUM_URLS"

if [[ -z "$validated_with_checksum_from_url" ]]; then
echo "Failed to validate '$wrapper_location'"
exit 1
else
echo "'$wrapper_location' is validated with sha256 checksum from '$validated_with_checksum_from_url'"
fi
}

WRAPPER_JARS=$(find . -type f -name "gradle-wrapper.jar")
if [ -z "${WRAPPER_JARS}" ]; then
echo "No gradle-wrapper.jar files found."
exit 1
else
while IFS= read -r wrapper_location; do
validate_checksum "$wrapper_location"
done <<< "$WRAPPER_JARS"
fi

0 comments on commit c0616cf

Please sign in to comment.