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 and strip_prefix for $# configs" 17 18_MISSING_MIRRORS=() 19for config in "$@"; do 20 TMP_FILE=$(mktemp -q /tmp/remotejdk.XXXXXX) 21 IFS=, read -r name url mirror_url hash strip_prefix <<< "${config}" 22 echo "fetching $name from $url to ${TMP_FILE}" 23 curl --silent -o ${TMP_FILE} -L "$url" 24 actual_hash=$(sha256sum ${TMP_FILE} | cut -d' ' -f1) 25 if [ "${hash}" != "${actual_hash}" ]; then 26 echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" 27 exit 1 28 fi 29 if [[ -z "${url##*.tar.gz}" ]]; then 30 root_dir=$(tar ztf ${TMP_FILE} --exclude='*/*') 31 elif [[ -z "${url##*.zip}" ]]; then 32 root_dir=$(unzip -Z1 ${TMP_FILE} | head -n1) 33 else 34 echo "ERROR: unexpected archive type for ${name}" 35 exit 1 36 fi 37 if [ "${root_dir}" != "${strip_prefix}/" ]; then 38 echo "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}/, got: ${root_dir}" 39 exit 1 40 fi 41 if [[ -n "${mirror_url}" ]]; then 42 echo "checking mirror: ${mirror_url}" 43 curl --silent --fail -I -L ${mirror_url} > /dev/null || { _MISSING_MIRRORS+=("${mirror_url}"); } 44 fi 45done 46 47if [[ ${#_MISSING_MIRRORS[@]} -gt 0 ]]; then 48 echo "Missing mirror URLs:" 49 for m in "${_MISSING_MIRRORS[@]}"; do 50 echo " ${m}" 51 done 52 exit 1 53fi