diff --git a/bin/redhat.bash b/bin/redhat.bash new file mode 100755 index 00000000000..1c5a5a44dd6 --- /dev/null +++ b/bin/redhat.bash @@ -0,0 +1,158 @@ +#!/usr/bin/env bash +set -e +set -Euo pipefail + +TEMP_DIR=$(mktemp -d) +trap 'rm -rf ${TEMP_DIR}' EXIT + +if [[ "$#" -lt 2 ]] +then + echo "Usage: ${0} metadata-directory checksum-directory" + exit 1 +fi + +# shellcheck source=bin/functions.bash +source "$(dirname "${0}")/functions.bash" + +VENDOR='redhat' +METADATA_DIR="${1}/${VENDOR}" +CHECKSUM_DIR="${2}/${VENDOR}" + +ensure_directory "${METADATA_DIR}" +ensure_directory "${CHECKSUM_DIR}" + +function normalize_version { + local jvm_impl="$1" + local name="$2" + local version="$3" + + if [[ "${jvm_impl}" == "openj9" ]] && [[ "${name}" =~ "openj9" ]] && [[ ! "${version}" =~ "openj9" ]] + then + local openj9_version + openj9_version=$(echo "${name}" | perl -pe 's/^.*(?:[_-](openj9[-_]\d+\.\d+\.\d+[a-z]?)){1,}.*\..+$/$1/') + echo "${version}.${openj9_version}" + else + echo "${version}" + fi +} + +function normalize_features { + declare -a features + if [[ "${1}" == "large" ]] + then + features+=("large_heap") + fi + echo "${features[@]}" +} + +function download { + local json + json=$(echo "$1" | base64 -d) + local filename + filename=$(jq -r '.name' <<< "${json}") + + local image_type + image_type="$(jq -r '.image_type' <<< "${json}")" + + case "${image_type}" in + jre|jdk) + ;; + *) + echo "Skipping non-JRE, non-JDK image ${filename}" + return 0 + ;; + esac + + local ext + # shellcheck disable=SC2016 + ext=$(echo "${filename}" | perl -pe 's/^.*\.(zip|tar\.gz|tar\.xz)$/$1/g') + local url + url=$(jq -r '.link' <<< "${json}") + local archive="${METADATA_DIR}/${filename}" + + local version + version="$(jq -r '.version' <<< "${json}")" + local jvm_impl + jvm_impl="$(jq -r '.jvm_impl' <<< "${json}")" + local normalized_version + normalized_version="$(normalize_version "${jvm_impl}" "${filename}" "${version}")" + + local metadata_file="${METADATA_DIR}/${filename}.json" + if [[ -f "${metadata_file}" ]] + then + echo "Skipping ${filename}" + else + if ! download_file "${url}" "${archive}" + then + echo "Failed to download ${url}" + return 0 + fi + + local md_json + md_json="$(metadata_json \ + "${VENDOR}" \ + "${filename}" \ + 'ga' \ + "${normalized_version}" \ + "$(jq -r '.java_version' <<< "${json}")" \ + "${jvm_impl}" \ + "$(normalize_os "$(jq -r '.os' <<< "${json}")")" \ + "$(normalize_arch "$(jq -r '.architecture' <<< "${json}")")" \ + "${ext}" \ + "$(jq -r '.image_type' <<< "${json}")" \ + "$(normalize_features "$(jq -r '.heap_size' <<< "${json}")")" \ + "${url}" \ + "$(hash_file 'md5' "${archive}" "${CHECKSUM_DIR}")" \ + "$(hash_file 'sha1' "${archive}" "${CHECKSUM_DIR}")" \ + "$(hash_file 'sha256' "${archive}" "${CHECKSUM_DIR}")" \ + "$(hash_file 'sha512' "${archive}" "${CHECKSUM_DIR}")" \ + "$(file_size "${archive}")" \ + "${filename}" + )" + + echo "${md_json}" > "${metadata_file}" + rm -f "${METADATA_DIR}/${filename}" + fi +} + +RELEASES_FILE="${TEMP_DIR}/available-releases.json" +download_file 'https://marketplace-api.adoptium.net/v1/info/available_releases/redhat' "${RELEASES_FILE}" +AVAILABLE_RELEASES=$(jq '.available_releases[]' "${RELEASES_FILE}") + +for release in ${AVAILABLE_RELEASES} +do + page=0 + while download_file "https://marketplace-api.adoptium.net/v1/assets/feature_releases/redhat/${release}?page=${page}&page_size=20&sort_order=ASC" "${TEMP_DIR}/release-${release}-${page}.json" + do + page=$((page+1)) + done +done + +FLATTEN_QUERY='add | +.[] | +[{ + release_type: .release_type, + java_version: .version_data.openjdk_version, + version: .version_data.semver, + binary: .binaries[], +}] | +.[] | +{ + release_type, + java_version, + version, + architecture: .binary.architecture, + os: .binary.os, + heap_size: .binary.heap_size, + image_type: .binary.image_type, + jvm_impl: .binary.jvm_impl, + link: .binary.package.link, + name: .binary.package.name +} | @base64' + +for json_b64 in $(jq -r -s "${FLATTEN_QUERY}" "${TEMP_DIR}"/release-*.json) +do + download "${json_b64}" +done + +jq -s -S . "${METADATA_DIR}"/java*.json > "${METADATA_DIR}/all.json" diff --git a/bin/update.bash b/bin/update.bash index a2eb0e84566..9b7b6d2a169 100755 --- a/bin/update.bash +++ b/bin/update.bash @@ -67,6 +67,7 @@ vendors=( "$(cmd 'kona21')" "$(cmd 'ibm')" "$(cmd 'jetbrains')" + "$(cmd 'redhat')" ) printf '%s\n' "${vendors[@]}" | parallel -P 4 --verbose "bash {} ${METADATA_DIR}/vendor ${CHECKSUM_DIR} ; echo \"{} EXIT CODE: \$?\""