Created
June 7, 2013 21:17
-
-
Save diginc/5732479 to your computer and use it in GitHub Desktop.
Based off of https://github.com/flexiondotorg/oab-java6/, but just downloads the .bin or .tar.gz for you. RUN: wget -O ./get-java.sh https://gist.github.com/diginc/5732479/raw/d23f9c35844fde9be8e1d05855ae7044a07ec771/get-java.sh; chmod +x get-java.sh;
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 | |
function usage() { echo "Allows scriptable downloading of official Java packages."; | |
echo -e "Options:\n -7: use latest java 7 version\n -v: specify version 6/7\n -u: specify the update version #\n -a: specify x64 or i586"; | |
exit 1; | |
} | |
# Defaults Opts | |
DESTINATION="./" | |
JAVA_VER=6 | |
JAVA_UPD=45 | |
JAVA_ARCH="x64" | |
# User Set Option overrides | |
OPTSTRING=7v:u:a:d: | |
while getopts ${OPTSTRING} OPT | |
do | |
case ${OPT} in | |
7) JAVA_VER=7 | |
JAVA_UPD=21;; | |
v) JAVA_VER=$OPTARG;; | |
u) JAVA_UPD=$OPTARG;; | |
a) JAVA_ARCH=$OPTARG;; | |
d) DESTINATION=$OPTARG;; | |
\?) usage;; | |
*) usage;; | |
esac | |
done | |
shift "$(( $OPTIND - 1 ))" | |
# Required Variables | |
if [ "${JAVA_VER}" -eq 6 ]; then | |
JAVA_EXT=.bin | |
else | |
JAVA_EXT=.tar.gz | |
fi | |
JAVA_BIN="jdk-${JAVA_VER}u${JAVA_UPD}-linux-${JAVA_ARCH}${JAVA_EXT}" | |
COOKIES="oraclelicensejdk-${JAVA_VER}u${JAVA_UPD}-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com"; | |
wget "http://www.oracle.com/technetwork/java/javase/downloads/index.html" -O /tmp/oab-index.html | |
DOWNLOAD_INDEX="$(egrep -o /technetwork/java/javase/downloads/jdk"$JAVA_VER(u$JAVA_UPD)?"-?downloads-[[:digit:]]+\\.html /tmp/oab-index.html | head -1)" | |
wget http://www.oracle.com/${DOWNLOAD_INDEX} -O /tmp/oab-download.html | |
DOWNLOAD_FOUND=`grep "jdk-${JAVA_VER}u${JAVA_UPD}-linux-${JAVA_ARCH}\." /tmp/oab-download.html` | |
if [ -z "${DOWNLOAD_FOUND}" ]; then | |
echo " [x] Getting previous releases download page " | |
if [ "${JAVA_VER}" -eq 6 ]; then | |
wget http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html -O /tmp/oab-download.html | |
else | |
wget http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase7-521261.html -O /tmp/oab-download.html | |
fi | |
fi | |
DOWNLOAD_URL=`grep ${JAVA_BIN} /tmp/oab-download.html | cut -d'{' -f2 | cut -d',' -f3 | cut -d'"' -f4` | |
if [ -z "${DOWNLOAD_URL}" ]; then | |
echo "No download found for ${JAVA_BIN}"; | |
else | |
wget --no-check-certificate --header="Cookie: ${COOKIES}" -c "${DOWNLOAD_URL}" -O ${DESTINATION}${JAVA_BIN} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment