Created
September 14, 2017 18:15
-
-
Save krzysbaranski/719f92605a00547a24dc605f1a5d37c3 to your computer and use it in GitHub Desktop.
Java JDK 8 install
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
#!/usr/bin/env bash | |
exec 1> >(logger -s -t $(basename $0)) 2>&1 | |
set -x | |
DOWNLOAD_DIR="/tmp/software/" | |
JDK_HOME="/opt/jdk8" | |
OUT_FILENAME="jdk-linux-x64.tar.gz" | |
URL="http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz" | |
if [ -f "${JDK_HOME}/bin/java" ]; then | |
VERSION=`${JDK_HOME}/bin/java -version 2>&1|head -n 1` | |
if [[ ${VERSION} == *"1.8.0_144"* ]] | |
then | |
echo already installed keeping ${JDK_HOME} ${VERSION} | |
exit 0; | |
fi | |
if [[ ${JDK_HOME} == *"/opt/jdk"* ]] | |
then | |
echo uninstalling ${JDK_HOME} ${VERSION} | |
rm -rf ${JDK_HOME} | |
fi | |
fi | |
if [ ! -d "${DOWNLOAD_DIR}" ]; then | |
echo "creating directory " ${DOWNLOAD_DIR} | |
mkdir -p ${DOWNLOAD_DIR} | |
fi | |
CHECKSUM=`curl --silent -o - 'https://www.oracle.com/webfolder/s/digest/8u144checksum.html'|grep jdk.*linux-x64.tar|awk '{print $3}' | awk -F '<' '{print $1}'` | |
#if [ -f "${DOWNLOAD_DIR}/${OUT_FILENAME}" ]; then | |
# echo "${CHECKSUM} ${DOWNLOAD_DIR}/${OUT_FILENAME}" | sha256sum -c | |
# if (($? > 0)); then | |
# mv -f ${DOWNLOAD_DIR}/${OUT_FILENAME} ${DOWNLOAD_DIR}/${OUT_FILENAME}.corrupted | |
# fi | |
#fi | |
if [ ! -f "${DOWNLOAD_DIR}/${OUT_FILENAME}" ]; then | |
echo "downloading $URL ..." | |
curl --silent -j -L -H "Cookie: oraclelicense=accept-securebackup-cookie" -o ${DOWNLOAD_DIR}/${OUT_FILENAME} "${URL}" | |
fi | |
# checksum | |
if [ -f "${DOWNLOAD_DIR}/${OUT_FILENAME}" ]; then | |
echo "${CHECKSUM} ${DOWNLOAD_DIR}/${OUT_FILENAME}" | sha256sum -c | |
if (($? > 0)); then | |
mv -f ${DOWNLOAD_DIR}/${OUT_FILENAME} ${DOWNLOAD_DIR}/${OUT_FILENAME}.corrupted | |
exit 1 | |
fi | |
fi | |
mkdir ${JDK_HOME} | |
tar --strip-components 1 -xzf ${DOWNLOAD_DIR}/${OUT_FILENAME} -C ${JDK_HOME} | |
if (($? > 0)); then | |
echo error extracting package | |
exit 1 | |
fi | |
chown -R root.root ${JDK_HOME} | |
TEMP_FILE=$(mktemp) | |
echo "export JAVA8_HOME=${JDK_HOME}" > ${TEMP_FILE} | |
echo "export PATH=\$PATH:${JDK_HOME}/bin" >> ${TEMP_FILE} | |
mv -f ${TEMP_FILE} /etc/profile.d/jdk8.sh | |
chmod 755 /etc/profile.d/jdk8.sh | |
echo setting env - JAVA8_HOME,PATH | |
VERSION=`${JDK_HOME}/bin/java -version 2>&1|head -n 1` | |
echo jdk installed ${VERSION} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment