Last active
July 18, 2017 15:28
-
-
Save sKwa/8b5ac00c55644e6cbb2b537e0ee00d53 to your computer and use it in GitHub Desktop.
Example how download latest JDK tar for Linux x64 platform programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# AUTHOR: Daniel Leybovich | |
BASE_URL="http://www.oracle.com" | |
PLATFORM="Linux x64" | |
ARCHIVE="tar.gz" | |
# get link to download page | |
SUFFIX=$(curl "${BASE_URL}/technetwork/java/javase/downloads/index.html" 2>/dev/null | grep 'name="JDK8"' | sed -nr 's/.*href="([^"]+)".*/\1/p') | |
LINK="${BASE_URL}${SUFFIX}" | |
# extract from download page link to latest version | |
DOWNLOAD_LINK=$(curl "${LINK}" 2>/dev/null | grep "${PLATFORM}" | grep -v demos | grep "${ARCHIVE}" | sed -nr 's/.*filepath":"([^"]+)".*/\1/p') | |
LATEST_VERSION=$(echo "${DOWNLOAD_LINK}" | sed -rn 's:.*/(8u[^/]+)/.*:\1:p') | |
CURRENT_VERSION=$(java -version 2>&1 | grep -m1 build | sed -rn 's/.*build ([^\)]+)\)/\1/p') | |
echo '-----------------------------------------------------' | |
echo "CURRENT VERSION : ${CURRENT_VERSION}" | |
echo "LATEST VERSION : ${LATEST_VERSION}" | |
echo "DOWNLOAD LINK : ${DOWNLOAD_LINK}" | |
echo '-----------------------------------------------------' | |
# download latest JDK | |
#wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" "${DOWNLOAD_LINK}" 2>/dev/null | |
# done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment