Skip to content

Instantly share code, notes, and snippets.

@serverhorror
Forked from P7h/jdk_download.sh
Created October 12, 2017 21:04
Show Gist options
  • Save serverhorror/cd40ed1f796a7813bb6966c768b8ab62 to your computer and use it in GitHub Desktop.
Save serverhorror/cd40ed1f796a7813bb6966c768b8ab62 to your computer and use it in GitHub Desktop.
Script to download JDK / JRE / Java binaries from Oracle website from terminal / shell / command line / command prompt
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
### Shell script to download Oracle JDK / JRE / Java binaries from Oracle website using terminal / command / shell prompt using wget.
### You can download all the binaries one-shot by just giving the BASE_URL.
### Script might be useful if you need Oracle JDK on Amazon EC2 env.
### Script is updated for every JDK release.
### Features:-
# 1. Resumes a broken / interrupted [previous] download, if any.
# 2. Renames the file to a proper name with including platform info.
# 3. Downloads the following from Oracle Website with one shell invocation.
# a. Windows 64 and 32 bit;
# b. Linux 64 and 32 bit;
# c. API Docs;
# d. You can add more to the list of downloads are per your requirement.
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
## Latest JDK9 version is JDK9u0 released on 21st Sep, 2017.
BASE_URL_9=http://download.oracle.com/otn-pub/java/jdk/9+181/jdk-9_
declare -a PLATFORMS=("linux-x64_bin.tar.gz" "windows-x64_bin.exe" "doc-all.zip")
# declare -a PLATFORMS=("linux-x64_bin.rpm" "linux-x64_bin.tar.gz" "osx-x64_bin.dmg" "windows-x64_bin.exe" "solaris-sparcv9_bin.tar.gz" "doc-all.zip")
for platform in "${PLATFORMS[@]}"
do
# wget -c --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" "${BASE_URL_9}${platform}"
curl -C - -LR#OH "Cookie: oraclelicense=accept-securebackup-cookie" -k "${BASE_URL_9}${platform}"
done
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
##### curl variant:
## • -C OR --continue-at ==> continuation from the last download, if any. And -C - for auto-detection.
## • -L OR --location ==> follow requested page, if moved to a different location.
## • -O OR --remote-name ==> name the local file same as remote file name.
## • -# OR --progress-bar ==> displays transfer progress as a simple progress bar. [not to be used with -s]
## • -H OR --header ==> header/@file to be included in the request.
## • -R OR --remote-time ==> local file will get the remote file timestamp.
## • -s OR --silent ==> quiet mode.
## • -S OR --show-error ==> show errors, if any.
curl -C - -L -O -# -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz"
curl -C - -L -O -R -s -S -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
##### wget variant:
## • -c OR --continue ==> resume getting a partially-downloaded file
## • -O OR --output-file=FILE ==> write documents to FILE
## • --no-check-certificate ==> don't validate the server's certificate
## • --no-cookies ==> don't use cookies
## • --header ==> insert STRING among the headers
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz"
wget -c -O "jdk-8u141-linux-x64.tar.gz" --no-check-certificate --no-cookies --header \
"Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
## Other notes picked from https://gist.github.com/laertis/749e9832e8c904ccda2d207a9112e663
## • --no-check-certificate
## Only required with wget 1.12 and earlier, which do not support
## Subject Alternative Name (SAN) certificates
## (mainly Red Hat Enterprise Linux 6.x and friends, such as CentOS).
## 1.13 was released in August 2011.
## • --no-cookies
## The combination --no-cookies --header "Cookie: name=value" is mentioned
## as the "official" cookie support, but not strictly required here.
## • --header "Cookie: oraclelicense=accept-securebackup-cookie"
## Since 15th March 2014 this cookie is provided to the user after accepting the License
## Agreementand is necessary for accessing the Java packages in download.oracle.com.
## The previous (and first) implementation in 27th March 2012 made use of the cookie
## gpw_e24=http%3A%2F%2Fwww.oracle.com[...]. Both cases remain unannounced to the public.
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
### Shell script to download Oracle JDK / JRE / Java binaries from Oracle website using terminal / command / shell prompt using wget / curl.
### You can download all the binaries one-shot by just providing one BASE_URL.
### Script might be useful if you need Oracle JDK on Amazon EC2 env.
### Script is updated for every JDK release.
### Features:-
# 1. Resumes a broken / interrupted [previous] download, if any.
# 2. Renames the file to a proper name with including platform info.
# 3. Downloads the following from Oracle Website with one shell invocation.
# a. Windows 64 and 32 bit;
# b. Linux 64 and 32 bit;
# c. API Docs;
# d. You can add more to the list of downloads are per your requirement.
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
## Latest JDK8 version is JDK8u144 released on 26th July, 2017.
BASE_URL_8=http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144
JDK_VERSION=`echo $BASE_URL_8 | rev | cut -d "/" -f1 | rev`
declare -a PLATFORMS=("-linux-arm32-vfp-hflt.tar.gz" "-linux-arm64-vfp-hflt.tar.gz" "-linux-i586.rpm" "-linux-i586.tar.gz" "-linux-x64.rpm" "-linux-x64.tar.gz" "-macosx-x64.dmg" "-solaris-sparcv9.tar.Z" "-solaris-sparcv9.tar.gz" "-solaris-x64.tar.Z" "-solaris-x64.tar.gz" "-windows-i586.exe" "-windows-x64.exe" "-docs-all.zip")
# declare -a PLATFORMS=("-linux-x64.tar.gz" "-windows-x64.exe" "-docs-all.zip")
for platform in "${PLATFORMS[@]}"
do
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" "${BASE_URL_8}${platform}"
### curl -C - -L -O -# -H "Cookie: oraclelicense=accept-securebackup-cookie" "${BASE_URL_8}${platform}"
done
##### Earlier versions:
## 8u141 => http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141
## 8u131 => http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131
## 8u121 => http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121
## 8u111 => http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111
## 8u101 => http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101
## v8u91 => http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91
## v8u77 => http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77
## v8u73 => http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73
## v8u71 => http://download.oracle.com/otn-pub/java/jdk/8u71-b15/jdk-8u71
## v8u65 => http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65
## v8u60 => http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60
## v8u51 => http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51
## v8u45 => http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45
## v8u40 => http://download.oracle.com/otn-pub/java/jdk/8u40-b25/jdk-8u40
## v8u31 => http://download.oracle.com/otn-pub/java/jdk/8u31-b13/jdk-8u31
## v8u25 => http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
##### Previous iteration commands [just for reference]:
wget -c -O "$JDK_VERSION$platform" --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
"${BASE_URL_8}${platform}"
curl -L -O -H "Cookie: oraclelicense=accept-securebackup-cookie" -k "${BASE_URL_8}${platform}"
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment