From 5a374051fd26e05dfc6b48226dcb2a0387f1b775 Mon Sep 17 00:00:00 2001 From: Damien Duportal Date: Mon, 2 Sep 2024 14:57:43 +0200 Subject: [PATCH 1/3] chore(adoptium install script) use long flags for 'curl' as a good practise Signed-off-by: Damien Duportal --- adoptium-get-jdk-link.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adoptium-get-jdk-link.sh b/adoptium-get-jdk-link.sh index b33e094e5..bfcea2a33 100755 --- a/adoptium-get-jdk-link.sh +++ b/adoptium-get-jdk-link.sh @@ -73,7 +73,7 @@ for ARCH in ${ARCHS}; do # Fetch the download URL from the Adoptium API URL="https://api.adoptium.net/v3/binary/version/jdk-${ENCODED_ARCHIVE_DIRECTORY}/${OS_TYPE}/${ARCH}/jdk/hotspot/normal/eclipse?project=jdk" - if ! RESPONSE=$(curl -fsI "${URL}"); then + if ! RESPONSE=$(curl --fail --silent --head "${URL}"); then echo "Error: Failed to fetch the URL for architecture ${ARCH}. Exiting with status 1." >&2 echo "Response: ${RESPONSE}" >&2 exit 1 @@ -91,7 +91,7 @@ for ARCH in ${ARCHS}; do # Use curl to check if the URL is reachable # If the URL is not reachable, print an error message and exit the script with status 1 - if ! curl -v -fs "${REDIRECTED_URL}" >/dev/null 2>&1; then + if ! curl --verbose --fail --silent "${REDIRECTED_URL}" >/dev/null 2>&1; then echo "${REDIRECTED_URL}" is not reachable for architecture "${ARCH}". >&2 exit 1 fi From ec112d4bab7dc512a8d7ed3bc880ab610abb659a Mon Sep 17 00:00:00 2001 From: Damien Duportal Date: Mon, 2 Sep 2024 14:59:29 +0200 Subject: [PATCH 2/3] chore(adoptium install script) show 'curl' errors when it fails (as silent mode is used) Signed-off-by: Damien Duportal --- adoptium-get-jdk-link.sh | 4 ++-- adoptium-install-jdk.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adoptium-get-jdk-link.sh b/adoptium-get-jdk-link.sh index bfcea2a33..fe558a3f1 100755 --- a/adoptium-get-jdk-link.sh +++ b/adoptium-get-jdk-link.sh @@ -73,7 +73,7 @@ for ARCH in ${ARCHS}; do # Fetch the download URL from the Adoptium API URL="https://api.adoptium.net/v3/binary/version/jdk-${ENCODED_ARCHIVE_DIRECTORY}/${OS_TYPE}/${ARCH}/jdk/hotspot/normal/eclipse?project=jdk" - if ! RESPONSE=$(curl --fail --silent --head "${URL}"); then + if ! RESPONSE=$(curl --fail --silent --show-error --head "${URL}"); then echo "Error: Failed to fetch the URL for architecture ${ARCH}. Exiting with status 1." >&2 echo "Response: ${RESPONSE}" >&2 exit 1 @@ -91,7 +91,7 @@ for ARCH in ${ARCHS}; do # Use curl to check if the URL is reachable # If the URL is not reachable, print an error message and exit the script with status 1 - if ! curl --verbose --fail --silent "${REDIRECTED_URL}" >/dev/null 2>&1; then + if ! curl --fail --silent --show-error "${REDIRECTED_URL}" >/dev/null 2>&1; then echo "${REDIRECTED_URL}" is not reachable for architecture "${ARCH}". >&2 exit 1 fi diff --git a/adoptium-install-jdk.sh b/adoptium-install-jdk.sh index 5c8812d04..aa45ac6ee 100755 --- a/adoptium-install-jdk.sh +++ b/adoptium-install-jdk.sh @@ -28,7 +28,7 @@ if ! DOWNLOAD_URL=$("${SCRIPT_DIR}"/adoptium-get-jdk-link.sh "${JAVA_VERSION}" " fi # Use curl to download the JDK archive from the URL -if ! curl --silent --location --output /tmp/jdk.tar.gz "${DOWNLOAD_URL}"; then +if ! curl --silent --show-error --location --output /tmp/jdk.tar.gz "${DOWNLOAD_URL}"; then echo "Error: Failed to download the JDK archive. Exiting with status 1." >&2 exit 1 fi From 713680f9c2d4d65db607e2127f6a0b8944ebc573 Mon Sep 17 00:00:00 2001 From: Damien Duportal Date: Mon, 2 Sep 2024 15:01:06 +0200 Subject: [PATCH 3/3] chore(adoptium install script) setup 'curl' to retry (exponential back off) on transient/connection errors - https://everything.curl.dev/usingcurl/downloads/retry.html Signed-off-by: Damien Duportal --- adoptium-get-jdk-link.sh | 4 ++-- adoptium-install-jdk.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adoptium-get-jdk-link.sh b/adoptium-get-jdk-link.sh index fe558a3f1..bbd8e1c98 100755 --- a/adoptium-get-jdk-link.sh +++ b/adoptium-get-jdk-link.sh @@ -73,7 +73,7 @@ for ARCH in ${ARCHS}; do # Fetch the download URL from the Adoptium API URL="https://api.adoptium.net/v3/binary/version/jdk-${ENCODED_ARCHIVE_DIRECTORY}/${OS_TYPE}/${ARCH}/jdk/hotspot/normal/eclipse?project=jdk" - if ! RESPONSE=$(curl --fail --silent --show-error --head "${URL}"); then + if ! RESPONSE=$(curl --fail --silent --show-error --retry 5 --retry-connrefused --head "${URL}"); then echo "Error: Failed to fetch the URL for architecture ${ARCH}. Exiting with status 1." >&2 echo "Response: ${RESPONSE}" >&2 exit 1 @@ -91,7 +91,7 @@ for ARCH in ${ARCHS}; do # Use curl to check if the URL is reachable # If the URL is not reachable, print an error message and exit the script with status 1 - if ! curl --fail --silent --show-error "${REDIRECTED_URL}" >/dev/null 2>&1; then + if ! curl --fail --silent --show-error --retry 5 --retry-connrefused "${REDIRECTED_URL}" >/dev/null 2>&1; then echo "${REDIRECTED_URL}" is not reachable for architecture "${ARCH}". >&2 exit 1 fi diff --git a/adoptium-install-jdk.sh b/adoptium-install-jdk.sh index aa45ac6ee..e572d1a01 100755 --- a/adoptium-install-jdk.sh +++ b/adoptium-install-jdk.sh @@ -28,7 +28,7 @@ if ! DOWNLOAD_URL=$("${SCRIPT_DIR}"/adoptium-get-jdk-link.sh "${JAVA_VERSION}" " fi # Use curl to download the JDK archive from the URL -if ! curl --silent --show-error --location --output /tmp/jdk.tar.gz "${DOWNLOAD_URL}"; then +if ! curl --silent --show-error --location --retry 5 --retry-connrefused --output /tmp/jdk.tar.gz "${DOWNLOAD_URL}"; then echo "Error: Failed to download the JDK archive. Exiting with status 1." >&2 exit 1 fi