Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertTheNerd/aa96c79ffcf4d417f193ffb406555667 to your computer and use it in GitHub Desktop.
Save RobertTheNerd/aa96c79ffcf4d417f193ffb406555667 to your computer and use it in GitHub Desktop.
get_jdk_linux_x64.sh
#!/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 <rpm|tar> <jdk_version>
# jdk_version: default 8
# rpm
EXT="tar.gz"
JDK_VERSION="8"
if [ -n "$1" ]; then
if [ "$1" == "tar" ]; then
EXT="tar.gz"
fi
fi
URL="http://www.oracle.com"
JDK_DOWNLOAD_URL1="${URL}/technetwork/java/javase/downloads/index.html"
JDK_DOWNLOAD_URL2=`curl -s $JDK_DOWNLOAD_URL1 | egrep -o "\/technetwork\/java/\javase\/downloads\/jdk${JDK_VERSION}-downloads-.+?\.html" | head -1`
if [ -z "$JDK_DOWNLOAD_URL2" ]; then
echo "Could not get jdk download url - $JDK_DOWNLOAD_URL1"
exit 1
fi
JDK_DOWNLOAD_URL3="${URL}${JDK_DOWNLOAD_URL2}"
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}" | tail -1`
wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
$JDK_DOWNLOAD_URL4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment