-
-
Save nikolauskrismer/d0818c3e27d18bc7a25e6c5c197f42c6 to your computer and use it in GitHub Desktop.
Get latest Oracle JDK package bash shell script
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
#!/bin/bash | |
# You must accept the Oracle Binary Code License | |
# http://www.oracle.com/technetwork/java/javase/terms/license/index.html | |
# | |
# @author 2014-2017 n0ts <[email protected]> (https://gist.github.com/n0ts/40dd9bd45578556f93e7) | |
# @author 2018 niko <[email protected]> (https://gist.github.com/nikolauskrismer/d0818c3e27d18bc7a25e6c5c197f42c6) | |
# | |
# usage: get_oracle_jdk_linux_x64.sh <jdk_version> <ext> | |
# | |
# jdk_version: 8,9 or 10 (default) | |
# ext: rpm (default) or tar.gz | |
jdk_version=${1:-10} | |
ext=${2:-rpm} | |
readonly url="http://www.oracle.com" | |
readonly jdk_download_url1="$url/technetwork/java/javase/downloads/index.html" | |
readonly jdk_download_url2=$( | |
curl -s $jdk_download_url1 | \ | |
egrep -o "\/technetwork\/java/\javase\/downloads\/jdk${jdk_version}-downloads-.+?\.html" | \ | |
head -1 | \ | |
cut -d '"' -f 1 | |
) | |
[[ -z "$jdk_download_url2" ]] && echo "Could not get jdk download url - $jdk_download_url1" >> /dev/stderr | |
readonly jdk_download_url3="${url}${jdk_download_url2}" | |
# thanks to @tstibbs | |
readonly jdk_download_url4=$( | |
curl -s $jdk_download_url3 | \ | |
egrep -o "http\:\/\/download.oracle\.com\/otn-pub\/java\/jdk\/([1-9][\.u0-9]*)(\+|\-)[b0-9]*\/[a-f0-9]+\/jdk-\1(-|_)linux-(x64|x64_bin).$ext" | \ | |
sort -r | \ | |
head -n 1 | |
) | |
for dl_url in ${jdk_download_url4[@]}; do | |
# thanks to @liedekef | |
curl -C - -LR#OH "Cookie: oraclelicense=accept-securebackup-cookie" -k $dl_url | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment