Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

github-actions[bot]
Copy link
Contributor

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!

Made with ❤️️ by updatecli
Copy link
Member

@lemeurherve lemeurherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lemeurherve
Copy link
Member

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

@lemeurherve lemeurherve merged commit 711cccd into master May 16, 2024
0 of 3 checks passed
@lemeurherve lemeurherve deleted the updatecli_master_1b37ca27e2cdecc5efc532fdb8ec51894d575ed829c56b35babbbf5ac6deb2bb branch May 16, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant