Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Automatically installs and configures Oracle JDK on Centos, OEL6, and OEL7.
#!/usr/bin/env bash
##
# Description:
#
# Automatically installs and configures Oracle JDK on Centos, OEL6, and OEL7.
#
if ! [[ "$(id -u)" = '0' ]] ; then
echo "\"$0\" must be run as root" 1>&2
exit 1
fi
set -x
set -o errexit
set -o pipefail
set -o nounset
DOWNLOAD_URL='http://download.oracle.com/otn-pub/java/jdk/8u152-b16/aa0333dd3019491ca4f6ddbe78cdb6d0/jdk-8u152-linux-x64.rpm'
SHA256_HASH='b95c69b10e41d0f91e1ae6ef51086025535a43235858326a5a8fd9c5693ecc28'
FILENAME="$(echo "${DOWNLOAD_URL}" | sed 's/.*\///')"
RPM_PKG_NAME="$(rpm -qp --queryformat '%{NAME}' "${FILENAME}")"
ALTERNATIVES_NAME="$(echo "${FILENAME}" | sed -e 's/-linux-x64\.rpm//' -e 's/-/1./' -e 's/u/.0_/')"
cd "$(dirname "$0")"
test -f "${FILENAME}" || curl --location --output "${FILENAME}" --header 'Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie' "${DOWNLOAD_URL}"
echo "${SHA256_HASH} ${FILENAME}" | sha256sum --check -
test -n "$(rpm -qa | grep "^${RPM_PKG_NAME}"'$')" || rpm -ivh "${FILENAME}"
alternatives --set java "/usr/java/${ALTERNATIVES_NAME}/jre/bin/java"
alternatives --set javac "/usr/java/${ALTERNATIVES_NAME}/bin/javac"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment