1#!/usr/bin/env bash 2# Copyright 2024 The Bazel Authors. All rights reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16echo "Checking hashes for $# configs" 17 18function download_and_check_hash() { 19 name=$1 20 url=$2 21 hash=$3 22 TMP_FILE=$(mktemp -q /tmp/remotejavatools.XXXXXX) 23 echo "fetching $name from $url to ${TMP_FILE}" 24 curl --silent -o ${TMP_FILE} -L "$url" 25 actual_hash=`sha256sum ${TMP_FILE} | cut -d' ' -f1` 26 if [ "${hash}" != "${actual_hash}" ]; then 27 echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" 28 exit 1 29 fi 30} 31 32for config in "$@"; do 33 IFS=, read -r name mirror_url gh_url hash <<< "${config}" 34 download_and_check_hash ${name} ${mirror_url} ${hash} 35 download_and_check_hash ${name} ${gh_url} ${hash} 36done