Skip to content

Instantly share code, notes, and snippets.

@approximatenumber
Forked from sr75/wget-jdk-oracle-install-example.txt
Last active December 8, 2016 09:03
Show Gist options
  • Save approximatenumber/9b7765acef568e9b9d97a6b824b6b864 to your computer and use it in GitHub Desktop.
Save approximatenumber/9b7765acef568e9b9d97a6b824b6b864 to your computer and use it in GitHub Desktop.
wget command to install Oracle JAVA JDK from stupid oracle website
#!/bin/bash
################################################################################
##
## Title: Oracle Java Installer
##
## Date: 03/27/2015
## Author: Mike G. aka metalcated and partially forked from n0ts
## Version: 0.2
##
################################################################################
# type can be jre or jdk
JAVA_TYPE="jdk"
JAVA_VERSION="8"
EXT="tar.gz"
# set base download location
URL="http://www.oracle.com"
DOWNLOAD_URL1="${URL}/technetwork/java/javase/downloads/index.html"
DOWNLOAD_URL2=$(curl -s $DOWNLOAD_URL1 | egrep -o "\/technetwork\/java/\javase\/downloads\/${JAVA_TYPE}${JAVA_VERSION}-downloads-.*\.html" | head -1)
# check to make sure we got to oracle
if [[ -z "$DOWNLOAD_URL2" ]]; then
echo "Could not to oracle - $DOWNLOAD_URL1"
exit 1
fi
# set download url
DOWNLOAD_URL3="$(echo ${URL}${DOWNLOAD_URL2}|awk -F\" {'print $1'})"
DOWNLOAD_URL4=$(curl -s "$DOWNLOAD_URL3" | egrep -o "http\:\/\/download.oracle\.com\/otn-pub\/java\/jdk\/[7-8]u[0-9]+\-(.*)+\/${JAVA_TYPE}-[7-8]u[0-9]+(.*)linux-x64.${EXT}"|tail -n1)
# check to make sure url exists
if [[ -z "$DOWNLOAD_URL4" ]]; then
echo "Could not get ${JAVA_TYPE} download url - $DOWNLOAD_URL4"
exit 1
fi
# set download file name
JAVA_INSTALL=$(echo $DOWNLOAD_URL4|cut -d "/" -f 8)
# download java
echo -e "\n\e[32mDownloading\e[0m: $DOWNLOAD_URL4"
while true;
do echo -n .;sleep 1;done &
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" $DOWNLOAD_URL4 > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
# end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment