#!/bin/sh #jinstall - Command line script to easily add new java directories to #'alternatives'. This sets the java as default, and you can switch your #default java with update-java-alternatives # #Copyright 2014 Bruce.Ingalls at gmail & Alin Andrei #GPL v3 Affero license at http://www.gnu.org/ #Downloads & discussion at http://www.webupd8.org/ #Tested on Ubuntu Oneiric; should require few changes for other modern Unix systems #Currently tested only with JDK, not JRE. # Not fully internationalized, including japanese man pages set -e VER='0.6alpha' case $(dpkg --print-architecture) in 'i386'|'i586'|'i686') arch=i386; dld=i586; SHA256SUM_TGZ="8062f34f69dd1f1991bff517df52da606c53f5fa0d6677ceb46df30e93b53a70" #must be modified for each release ;; 'amd64' ) arch=amd64; dld=x64; SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f" #must be modified for each release ;; * ) echo "Please report to author unsupported platform '`uname -m`'."; echo "Proceeding without web browser plugin support"; arch=''; esac ########Variables if [ ! $arch = "arm" ]; then JAVA_VERSION=8u151 #must be modified for each release jdk-8u5-linux-x64.tar.gz J_DIR=jdk1.8.0_151 #must be modified for each release FILENAME=jdk-${JAVA_VERSION}-linux-${dld}.tar.gz #PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/$FILENAME #must be modified for each release for JAVA_VERSION_OLD2 in `seq 1 150`; do #must be modified for each release FILENAMES_OLD2="jdk-8u${JAVA_VERSION_OLD2}-linux-${dld}*.tar.gz $FILENAMES_OLD2" done fi J_INSTALL_DIR=/usr/lib/jvm/java-8-oracle ########Create dirs mkdir -p /var/cache/oracle-jdk8-installer mkdir -p /usr/lib/jvm mkdir -p /usr/lib/oracle-jdk8-installer-unpackdir #without this, an error is displayed if the folder doesn't exist: mkdir -p /usr/lib/mozilla/plugins if [ $arch = "arm" ]; then #apparently this dir doesn't exist on some arm machines mkdir -p /usr/share/man/man1 fi ############# . /usr/share/debconf/confmodule fp_exit_with_error() { echo $1 echo "Oracle JDK 8 is NOT installed." db_fset oracle-java8-installer/local seen false exit 1 } OLDDIR=/usr/lib/oracle-jdk8-installer-unpackdir NEWDIR=/var/cache/oracle-jdk8-installer safe_move() { [ ! -f $OLDDIR/$1 ] || [ -f $NEWDIR/$1 ] || mv $OLDDIR/$1 $NEWDIR/$1 2> /dev/null || true [ ! -f $OLDDIR/$1 ] || [ ! -f $NEWDIR/$1 ] || rm -f $OLDDIR/$1 2> /dev/null || true } # lliurex LLIUREX CHANGES ORACLE_DIR=/var/cache/oracle-jdk8-installer cd $ORACLE_DIR tar xzf $FILENAME || fp_exit_with_error "cannot unpack jdk8" # LLX DONE # Copy JDK to the right dir mv $J_DIR java-8-oracle rm -rf /usr/lib/jvm/java-8-oracle cp -rf java-8-oracle /usr/lib/jvm/ # There's no javaws on arm if [ ! $arch = "arm" ]; then # Install javaws-wrapper.sh mv $J_INSTALL_DIR/jre/bin/javaws $J_INSTALL_DIR/jre/bin/javaws.real install -m 755 javaws-wrapper.sh $J_INSTALL_DIR/jre/bin/javaws fi # Install jar.binfmt install -m 755 jar.binfmt $J_INSTALL_DIR/jre/lib/jar.binfmt # Install OpenJDK's font config install -m 755 fontconfig.Ubuntu.properties $J_INSTALL_DIR/jre/lib/ # Clean up rm -rf java-8-oracle # To add when an older version exists: # safe_move jdk-7u2-linux-x64.tar.gz #must be modified for each release # safe_move jdk-7u2-linux-i586.tar.gz #must be modified for each release rmdir $OLDDIR 2> /dev/null || true #remove previous versions, if they exist db_fset oracle-java8-installer/local seen false # This step is optional, recommended, and affects code below. ls $J_INSTALL_DIR/man/man1/*.1 >/dev/null 2>&1 && \ gzip -9 $J_INSTALL_DIR/man/man1/*.1 >/dev/null 2>&1 #Increment highest version by 1. #Also assumes all Java helper programs (javaws, jcontrol, etc) at same version as java. #These helpers should be slaves, or in the same path as java; thus, a reasonable assumption. LATEST=1 LATEST=$((`LANG=C update-alternatives --display java | grep ^/ | sed -e 's/.* //g' | sort -n | tail -1`+1)) PRIORITY=1081 #create .java-8-oracle.jinfo file header: if [ -e /usr/lib/jvm/.java-8-oracle.jinfo ]; then rm -f /usr/lib/jvm/.java-8-oracle.jinfo fi echo "name=java-8-oracle alias=java-8-oracle priority=$PRIORITY section=non-free " > /usr/lib/jvm/.java-8-oracle.jinfo #link JRE files for f in $J_INSTALL_DIR/jre/bin/*; do name=`basename $f`; if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then #some files, like jvisualvm might not be links if [ -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then if [ ! $arch = "arm" ]; then update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $PRIORITY --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-8-oracle.jinfo else # There's no javaws, jvisualvm or jmc on arm [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && [ ! $name = "jmc" ] && update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $PRIORITY --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && [ ! $name = "jmc" ] && echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-8-oracle.jinfo fi else #no man pages available # [ ! $name = "javaws.real" ] = skip javaws.real [ ! $name = "javaws.real" ] && update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $PRIORITY [ ! $name = "javaws.real" ] && echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-8-oracle.jinfo fi fi done #link JRE not in jre/bin [ -f $J_INSTALL_DIR/jre/lib/jexec ] && update-alternatives --install /usr/bin/jexec jexec $J_INSTALL_DIR/jre/lib/jexec $PRIORITY --slave /usr/share/binfmts/jar jexec-binfmt $J_INSTALL_DIR/jre/lib/jar.binfmt && echo "jre jexec $J_INSTALL_DIR/jre/lib/jexec" >> /usr/lib/jvm/.java-8-oracle.jinfo #This will issue ignorable warnings for alternatives that are not part of a group #Link JDK files with/without man pages if [ -d "$J_INSTALL_DIR/man/man1" ];then for f in $J_INSTALL_DIR/man/man1/*; do name=`basename $f .1.gz`; #some files, like jvisualvm might not be links. Further assume this for corresponding man page if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then if [ ! -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then name=`basename $f .1`; #handle any legacy uncompressed pages fi if [ ! -e $J_INSTALL_DIR/jre/bin/$name ]; then #don't link already linked JRE files if [ ! $arch = "arm" ]; then update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $PRIORITY --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-8-oracle.jinfo else # There's no javaws, jvisualvm or jmc on arm [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && [ ! $name = "jmc" ] && update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $PRIORITY --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz [ ! $name = "javaws" ] && [ ! $name = "jvisualvm" ] && [ ! $name = "jmc" ] && echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-8-oracle.jinfo fi fi fi done else #no man pages available for f in $J_INSTALL_DIR/bin/*; do name=`basename $f`; if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then #some files, like jvisualvm might not be links if [ ! -e $J_INSTALL_DIR/jre/bin/$name ]; then #don't link already linked JRE files update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $PRIORITY echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-8-oracle.jinfo fi fi done fi # Hide javaws and jvisualvm desktop files on arm since these files don't exist on this architecture if [ $arch = "arm" ]; then echo "NoDisplay=true" >> /usr/share/applications/JB-javaws-jdk8.desktop echo "NoDisplay=true" >> /usr/share/applications/JB-jvisualvm-jdk8.desktop fi # Use cacerts form ca-certificates-java if it's installed: if [ -e /etc/ssl/certs/java/cacerts ]; then cd /usr/lib/jvm/java-8-oracle/jre/lib/security mv cacerts cacerts.original ln -s /etc/ssl/certs/java/cacerts . fi # Place security config files in /etc so they are not overwritten on upgrade mkdir -p /etc/java-8-oracle/security for configfile in blacklist blacklisted.certs java.policy java.security javaws.policy trusted.libraries do if [ ! -e /etc/java-8-oracle/security/"$configfile" ] && [ -e /usr/lib/jvm/java-8-oracle/jre/lib/security/"$configfile" ]; then mv /usr/lib/jvm/java-8-oracle/jre/lib/security/"$configfile" /etc/java-8-oracle/security/ else rm -f /usr/lib/jvm/java-8-oracle/jre/lib/security/"$configfile" fi done for configfile in blacklist blacklisted.certs java.policy java.security javaws.policy trusted.libraries do if [ ! -e /usr/lib/jvm/java-8-oracle/jre/lib/security/"$configfile" ] && [ -e /etc/java-8-oracle/security/"$configfile" ]; then ln -s /etc/java-8-oracle/security/"$configfile" /usr/lib/jvm/java-8-oracle/jre/lib/security/ fi done # register binfmt; ignore errors, the alternative may already be # registered by another JRE. if which update-binfmts >/dev/null && [ -r /usr/share/binfmts/jar ]; then update-binfmts --package oracle-java8 --import jar || true fi # Install Firefox (and compatible) plugin. $arch will be empty for unknown platform # No plugin for arm architecture yet [ -f $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so ] && \ update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so $PRIORITY && \ echo "plugin mozilla-javaplugin.so $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so" >> /usr/lib/jvm/.java-8-oracle.jinfo && \ echo "Oracle JRE 8 browser plugin installed" echo "Oracle JDK 8 installed" echo "" echo "#####Important########" echo "To set Oracle JDK8 as default, install the \"oracle-java8-set-default\" package." echo "E.g.: sudo apt install oracle-java8-set-default." #DEBHELPER# exit 0 # vim: ts=2 sw=2