Skip to content

Instantly share code, notes, and snippets.

@bionix
Forked from n0ts/get_oracle_jdk_x64.sh
Created June 12, 2017 08:37
Show Gist options
  • Save bionix/7a5f4601ef0535dd8e24a398fef944a1 to your computer and use it in GitHub Desktop.
Save bionix/7a5f4601ef0535dd8e24a398fef944a1 to your computer and use it in GitHub Desktop.
Get latest Oracle JDK package bash shell script
#!/bin/bash
# You must accept the Oracle Binary Code License
# http://www.oracle.com/technetwork/java/javase/terms/license/index.html
# usage: get_jdk.sh <ext> <jdk_version>
# ext: rpm
# jdk_version: default 8
ext=rpm
jdk_version=8
if [ -n "$1" ]; then
if [ "$1" == "tar" ]; then
ext="tar.gz"
fi
fi
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" ]] && error "Could not get jdk download url - $jdk_download_url1"
readonly jdk_download_url3="${url}${jdk_download_url2}"
readonly jdk_download_url4=$(curl -s $jdk_download_url3 | egrep -o "http\:\/\/download.oracle\.com\/otn-pub\/java\/jdk\/[7-8]u[0-9]+\-(.*)+\/jdk-[7-8]u[0-9]+(.*)linux-x64.$ext")
for dl_url in ${jdk_download_url4[@]}; do
wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
-N $dl_url
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment