Last active
May 27, 2017 12:08
-
-
Save patelkunal/691d4790c968cfed27798e838bce3393 to your computer and use it in GitHub Desktop.
java8-serverjre-installation-script
This file contains hidden or 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/sh | |
# This is a quick script to download and install Oracle's Java 8 Server JRE | |
# It was made with Ubuntu 16.04 LTS in mind, and installs to /usr/local | |
# curl pipe this script to sh if you enjoy the thrill of getting into an internet stranger's van | |
prefix="/usr/local" | |
java_url="http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/server-jre-8u131-linux-x64.tar.gz" | |
dl_file="/tmp/oracle-java8.tar.gz" | |
ohshi() | |
{ | |
tput setaf 1 | |
echo "${1}" | |
tput sgr0 | |
exit 1 | |
} | |
java_link="${prefix}/bin/java" | |
if [ -e "${java_link}" ]; then | |
[ ! -h "${java_link}" ] && oshi "${java_link} exists and is not a symlink!" | |
java_real=$(readlink -f "${java_link}") | |
if [ ! -e "${java_real}" ]; then | |
rm "${java_link}" | |
echo "Removing old symlink to java since its target is missing" | |
else | |
ohshi "You already seem to have java installed at ${java_link} (${java_real})" | |
fi | |
fi | |
# You accept and read Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX | |
# http://www.oracle.com/technetwork/java/javase/terms/license/index.html | |
# License Addendum: - You will not hold me liable for shit | |
# - You will not use excessive pressure on your keyboard when typing out this script's name | |
if [ ! -e "${dl_file}" ]; then | |
curl -b oraclelicense="accept-securebackup-cookie" -o "${dl_file}" -L "${java_url}" | |
if [ $? -ne 0 -o ! -e "${dl_file}" ]; then | |
ohshi "Could not download java" | |
fi | |
fi | |
jdk_dir=$(tar -tf "${dl_file}" | grep -o '^[^/]\+' | sort -u) | |
java_home="${prefix}/lib/${jdk_dir}" | |
tar zxf "${dl_file}" -C "${prefix}/lib" | |
if [ ! -d "${java_home}" ]; then | |
ohshi "Extracted directory doesn't exist! ${java_home}" | |
fi | |
ln -s "${java_home}/bin/java" "${prefix}/bin/java" | |
printenv | grep -e "^JAVA_HOME" && echo "FYI: You already have JAVA_HOME somewhere in your environment. You may have to unset it." | |
sed -e '/JAVA_HOME/ s/^#*/#/' -i /etc/environment | |
echo "JAVA_HOME=\"${java_home}\"" >> /etc/environment | |
echo "Set JAVA_HOME in /etc/environment to \"${java_home}\"" | |
echo "${PATH}" | grep -q "${prefix}/bin" || echo "You need to add ${prefix}/bin to your PATH" | |
rm "${dl_file}" | |
echo "All done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment