Skip to content

Instantly share code, notes, and snippets.

@tweekmonster
Created May 6, 2015 15:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tweekmonster/d065391c8c48125032a3 to your computer and use it in GitHub Desktop.
Save tweekmonster/d065391c8c48125032a3 to your computer and use it in GitHub Desktop.
Script for installing Oracle's Java 8 Server JRE on Ubuntu 14.04 LTS
#!/bin/sh
# This is a quick script to download and install Oracle's Java 8 Server JRE
# It was made with Ubuntu 14.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/8u45-b14/server-jre-8u45-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