Created
October 4, 2017 18:12
-
-
Save anthonyclarka2/dfb3d3947491aa1d13540dcfdff07dbb to your computer and use it in GitHub Desktop.
install the JDK from a local mirror somewhere
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 -e | |
JDK_MAJOR_VERSION='8' | |
JDK_MINOR_VERSION='66' | |
JDK_FILENAME="jdk-${JDK_MAJOR_VERSION}u${JDK_MINOR_VERSION}-linux-x64.tar.gz" | |
JDK_DOWNLOAD_BASE='http://local-mirror.example.com/miscfiles/' | |
JDK_DOWNLOAD_URL="${JDK_DOWNLOAD_BASE}${JDK_FILENAME}" | |
JAVA_BASE_DIR="/opt/java" | |
JDK_TARBALL="${JAVA_BASE_DIR}/.download/${JDK_FILENAME}" | |
JDK_HOME="${JAVA_BASE_DIR}/jdk1.${JDK_MAJOR_VERSION}.0_${JDK_MINOR_VERSION}" | |
CHECKSUM="7e95ad5fa1c75bc65d54aaac9e9986063d0a442f39a53f77909b044cef63dc0a" | |
function install_symlink() { | |
local DEFAULT_JDK_HOME="${JAVA_BASE_DIR}/jdk1.${JDK_MAJOR_VERSION}" | |
if [[ "$(readlink "${DEFAULT_JDK_HOME}")" != "${JDK_HOME}" ]]; then | |
echo " Resetting symlink from ${JDK_HOME} ${DEFAULT_JDK_HOME}" | |
rm -fr "${DEFAULT_JDK_HOME}" | |
ln -sv "${JDK_HOME}" "${DEFAULT_JDK_HOME}" | |
fi | |
"${DEFAULT_JDK_HOME}/bin/java" -version | |
} | |
if [[ ! -d "${JAVA_BASE_DIR}" ]]; then | |
echo " Creating ${JAVA_BASE_DIR}" | |
mkdir "${JAVA_BASE_DIR}" | |
fi | |
if [[ ! -d "${JAVA_BASE_DIR}/.download" ]]; then | |
echo " Creating ${JAVA_BASE_DIR}/.download" | |
mkdir "${JAVA_BASE_DIR}/.download" | |
fi | |
echo " Checking for existence of java jdk1.${JDK_MAJOR_VERSION}.0_${JDK_MINOR_VERSION}" | |
if [[ ! -x "${JDK_HOME}/bin/java" ]]; then | |
if [[ ! -f "${JDK_TARBALL}" ]]; then | |
echo " Downloading jdk1.${JDK_MAJOR_VERSION}.0_${JDK_MINOR_VERSION} from ${JDK_DOWNLOAD_URL}" | |
wget --no-cookies --no-check-certificate \ | |
--output-document="${JDK_TARBALL}" \ | |
"${JDK_DOWNLOAD_URL}" | |
echo " Checking SHA256 signature of downloaded file" | |
if [[ $(sha256sum "" | cut -f1) != "${CHECKSUM}" ]]; then | |
echo " Signature does not match!" | |
echo " Check that the file is correct and that this script is updated correctly!" | |
exit 1 | |
else | |
echo " Signature is OK!" | |
fi | |
fi | |
echo " Extracting jdk1.${JDK_MAJOR_VERSION}.0_${JDK_MINOR_VERSION} to ${JAVA_BASE_DIR}" | |
tar xzf "${JDK_TARBALL}" -C "${JAVA_BASE_DIR}" | |
echo " Changing ownership of ${JDK_HOME}" | |
chown -R root:root "${JDK_HOME}" | |
else | |
echo " Everything looks good!" | |
fi | |
install_symlink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment