jenkinsci / docker-agent

Jenkins agent (base image) and inbound agent Docker images
https://hub.docker.com/r/jenkins/inbound-agent/
MIT License
282 stars 228 forks source link

Update `adoptium-get-jdk-link.sh` script content #812

Closed github-actions[bot] closed 3 months ago

github-actions[bot] commented 3 months ago

Update `adoptium-get-jdk-link.sh` script content

Update script content

1 file(s) updated with "#!/bin/sh\n\n# Check if at least one argument was passed to the script\n# If one argument was passed and JAVA_VERSION is set, assign the argument to OS\n# If two arguments were passed, assign them to JAVA_VERSION and OS respectively\n# If three arguments were passed, assign them to JAVA_VERSION, OS and ARCHS respectively\n# If not, check if JAVA_VERSION and OS are already set. If they're not set, exit the script with an error message\nif [ $# -eq 1 ] && [ -n \"${JAVA_VERSION}\" ]; then\n OS=\"${1}\"\nelif [ $# -eq 2 ]; then\n JAVA_VERSION=\"${1}\"\n OS=\"${2}\"\nelif [ $# -eq 3 ]; then\n JAVA_VERSION=\"${1}\"\n OS=\"${2}\"\n ARCHS=$3\nelif [ -z \"${JAVA_VERSION}\" ] && [ -z \"${OS}\" ]; then\n echo \"Error: No Java version and OS specified. Please set the JAVA_VERSION and OS environment variables or pass them as arguments.\" >&2\n exit 1\nelif [ -z \"${JAVA_VERSION}\" ]; then\n echo \"Error: No Java version specified. Please set the JAVA_VERSION environment variable or pass it as an argument.\" >&2\n exit 1\nelif [ -z \"${OS}\" ]; then\n OS=\"${1}\"\n if [ -z \"${OS}\" ]; then\n echo \"Error: No OS specified. Please set the OS environment variable or pass it as an argument.\" >&2\n exit 1\n fi\nfi\n\n# Check if ARCHS is set. If it's not set, assign the current architecture to it\nif [ -z \"${ARCHS}\" ]; then\n ARCHS=$(uname -m | sed -e 's/x86_64/x64/' -e 's/armv7l/arm/')\nelse\n # Convert ARCHS to an array\n OLD_IFS=\"${IFS}\"\n IFS=','\n set -- \"${ARCHS}\"\n ARCHS=\"\"\n for arch in \"$@\"; do\n ARCHS=\"${ARCHS} ${arch}\"\n done\n IFS=\"${OLD_IFS}\"\nfi\n\n# Check if jq and curl are installed\n# If they are not installed, exit the script with an error message\nif ! command -v jq >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then\n echo \"jq and curl are required but not installed. Exiting with status 1.\" >&2\n exit 1\nfi\n\n# Replace underscores with plus signs in JAVA_VERSION\nARCHIVE_DIRECTORY=$(echo \"${JAVA_VERSION}\" | tr '_' '+')\n\n# URL encode ARCHIVE_DIRECTORY\nENCODED_ARCHIVE_DIRECTORY=$(echo \"${ARCHIVE_DIRECTORY}\" | xargs -I {} printf %s {} | jq \"@uri\" -jRr)\n\n# Determine the OS type for the URL\nOS_TYPE=\"linux\"\nif [ \"${OS}\" = \"alpine\" ]; then\n OS_TYPE=\"alpine-linux\"\nfi\nif [ \"${OS}\" = \"windows\" ]; then\n OS_TYPE=\"windows\"\nfi\n\n# Initialize a variable to store the URL for the first architecture\nFIRST_ARCH_URL=\"\"\n\n# Loop over the array of architectures\nfor ARCH in ${ARCHS}; do\n # Fetch the download URL from the Adoptium API\n URL=\"https://api.adoptium.net/v3/binary/version/jdk-${ENCODED_ARCHIVE_DIRECTORY}/${OS_TYPE}/${ARCH}/jdk/hotspot/normal/eclipse?project=jdk\"\n\n if ! RESPONSE=$(curl -fsI \"${URL}\"); then\n echo \"Error: Failed to fetch the URL for architecture ${ARCH}. Exiting with status 1.\" >&2\n echo \"Response: ${RESPONSE}\" >&2\n exit 1\n fi\n\n # Extract the redirect URL from the HTTP response\n REDIRECTED_URL=$(echo \"${RESPONSE}\" | grep Location | awk '{print $2}' | tr -d '\\r')\n\n # If no redirect URL was found, exit the script with an error message\n if [ -z \"${REDIRECTED_URL}\" ]; then\n echo \"Error: No redirect URL found for architecture ${ARCH}. Exiting with status 1.\" >&2\n echo \"Response: ${RESPONSE}\" >&2\n exit 1\n fi\n\n # Use curl to check if the URL is reachable\n # If the URL is not reachable, print an error message and exit the script with status 1\n if ! curl -v -fs \"${REDIRECTED_URL}\" >/dev/null 2>&1; then\n echo \"${REDIRECTED_URL}\" is not reachable for architecture \"${ARCH}\". >&2\n exit 1\n fi\n\n # If FIRST_ARCH_URL is empty, store the current URL\n if [ -z \"${FIRST_ARCH_URL}\" ]; then\n FIRST_ARCH_URL=${REDIRECTED_URL}\n fi\ndone\n\n# If all downloads are successful, print the URL for the first architecture\necho \"${FIRST_ARCH_URL}\"\n": * adoptium-get-jdk-link.sh

GitHub Action workflow link

Updatecli logo

Created automatically by Updatecli

Options:

Most of Updatecli configuration is done via its manifest(s).

  • If you close this pull request, Updatecli will automatically reopen it, the next time it runs.
  • If you close this pull request and delete the base branch, Updatecli will automatically recreate it, erasing all previous commits made.

Feel free to report any issues at github.com/updatecli/updatecli.
If you find this tool useful, do not hesitate to star our GitHub repository as a sign of appreciation, and/or to tell us directly on our chat!

lemeurherve commented 3 months ago

Shellcheck changes only, already tested in this repository, reviewed and approved in https://github.com/jenkins-infra/shared-tools/pull/148, merging now to avoid wasting CI resources.