Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Created June 27, 2017 16:01
Show Gist options
  • Save arehmandev/6f0b0fcc7d98ce8dd09f1fb666b6dea7 to your computer and use it in GitHub Desktop.
Save arehmandev/6f0b0fcc7d98ce8dd09f1fb666b6dea7 to your computer and use it in GitHub Desktop.
#!/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