Skip to content

Instantly share code, notes, and snippets.

@miguelbaldi
Last active December 25, 2015 20:39
Show Gist options
  • Save miguelbaldi/7036508 to your computer and use it in GitHub Desktop.
Save miguelbaldi/7036508 to your computer and use it in GitHub Desktop.
Bash script for installing Oracle JDK|JRE as a Debian Package and optionally configuring java plugin for Mozilla browser. Just follow the instructions: ./install-oracle-jdk.sh Needs sudo installed and configured. Tested on Debian Jessie (testing)
#!/bin/bash
# ---------------------------------------------------------------------------
# install-oracle-jdk.sh - Oracle Java JDK/JRE Debian installer
# Copyright 2013, Miguel A. Baldi Horlle ([email protected])
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License at (http://www.gnu.org/licenses/) for
# more details.
usage() {
echo "Usage: $0 [-p <mozilla|chrome>] jdk-VERSION-linux-ARCH.tar.gz" 1>&2;
echo "Examples" 1>&2;
echo "" 1>&2;
echo " Installs JDK without browser plugin." 1>&2;
echo " terminal>$0 jdk-7u45-linux-x64.tar.gz" 1>&2;
echo "" 1>&2;
echo " Installs JDK with Mozilla(Firefox|Iceweasel) browser plugin." 1>&2;
echo " terminal>$0 -p mozilla jdk-7u45-linux-x64.tar.gz" 1>&2;
echo "" 1>&2;
echo " Installs JDK with Google Chrome(Chromium) browser plugin." 1>&2;
echo " terminal>$0 -p chrome jdk-7u45-linux-x64.tar.gz" 1>&2;
exit 1;
}
check_tools() {
hash make-jpkg 2>/dev/null || {
echo >&2 "In order to run we require 'make-jpkg' but it's not installed. Aborting.";
echo >&2 "Debian: apt-get install java-package";
exit 1;
}
hash sudo 2>/dev/null || {
echo >&2 "In order to run we require 'sudo' but it's not installed. Aborting.";
echo >&2 "Debian: apt-get install sudo";
exit 1;
}
}
while getopts ":p:" o; do
case "${o}" in
p)
p="${OPTARG}"
((p == "mozilla" || p == "chrome")) || usage
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "$1" ]; then
usage
fi
echo "Checking tools..."
check_tools
echo "Generating Debian package..."
MAKE_PKG_RESULT="$(yes | make-jpkg $1 2>&1)"
EXEC_CMD=$(echo -e "$MAKE_PKG_RESULT" | grep -o -E '([[:space:]])+(\w*(\.)*(\-)*(\_)*(\+)*)*.deb' | xargs echo)
## Installing debian package
echo "Installing Debian package $(echo $EXEC_CMD | awk '{ print $3 }')"
echo "In order to install the package, we need sudo here. Sorry"
sudo dpkg -i $EXEC_CMD
echo ""
if [ -n "${p}" ]; then
case "${p}" in
mozilla)
echo "Installing mozilla java plugin..."
update-alternatives --get-selections | grep "java\|jvm"
sudo update-alternatives --quiet --install /usr/lib/mozilla/plugins/libnpjp2.so mozilla-javaplugin.so $(dpkg -L $(dpkg -l | awk '{print $2}' |grep '^oracle' | grep 'j2re\|jre\|jdk') | grep libnpjp2.so) 316
sudo update-alternatives --quiet --set mozilla-javaplugin.so $(dpkg -L $(dpkg -l |awk '{print $2}' | grep '^oracle' | grep 'j2re\|jre\|jdk' ) | grep libnpjp2.so)
;;
chrome)
echo "Needs implementation!"
;;
esac
fi
sudo update-alternatives --config java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment