Skip to content

Instantly share code, notes, and snippets.

@davidfuhr
Created December 8, 2015 11:34
Show Gist options
  • Save davidfuhr/07407e865cc8255d810c to your computer and use it in GitHub Desktop.
Save davidfuhr/07407e865cc8255d810c to your computer and use it in GitHub Desktop.
Extracts and installs jdk package
#!/bin/bash
set -eou pipefail
if [ ! -f "$1" ]; then
echo $1 is not readable.
exit 1
fi
TEMPDIR=`mktemp -d`
cleanup()
{
rm -r $TEMPDIR
return $?
}
trap cleanup SIGINT
tar -C $TEMPDIR -xzf $1
cd $TEMPDIR
JDK=`ls`
sudo mv $JDK/ /opt/
sudo chown -R root:root /opt/$JDK
sudo ln -nsf /opt/$JDK /opt/jdk
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/$JDK/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/$JDK/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/$JDK/bin/javaws" 1
sudo update-alternatives --install "/usr/bin/jar" "jar" "/opt/$JDK/bin/jar" 1
sudo update-alternatives --install "/usr/lib/mozilla/plugins/mozilla-javaplugin.so" "mozilla-javaplugin.so" "/opt/$JDK/jre/lib/amd64/libnpjp2.so" 1
sudo update-alternatives --set "java" "/opt/$JDK/bin/java"
sudo update-alternatives --set "javac" "/opt/$JDK/bin/javac"
sudo update-alternatives --set "javaws" "/opt/$JDK/bin/javaws"
sudo update-alternatives --set "jar" "/opt/$JDK/bin/jar"
sudo update-alternatives --set "mozilla-javaplugin.so" "/opt/$JDK/jre/lib/amd64/libnpjp2.so"
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment