#!/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 'amd64' ) arch=amd64; dld=x64; SHA256SUM_TGZ="2cdaf0ff92d0829b510edd883a4ac8322c02f2fc1beae95d048b6716076bc014" #must be modified for each release ;; * ) echo "Please report to author unsupported platform '`uname -m`'."; echo "Proceeding without web browser plugin support"; arch=''; esac JAVA_VERSION_MAJOR=9.0.1 # JAVA_VERSION_MINOR=11 #must be modified for each release J_DIR=jdk-${JAVA_VERSION_MAJOR} #must be modified for each release FILENAME=jdk-${JAVA_VERSION_MAJOR}_linux-x64_bin.tar.gz J_INSTALL_DIR=/usr/lib/jvm/java-9-x64-oracle ########Create dirs mkdir -p /var/cache/oracle-jdk9-x64-installer mkdir -p /usr/lib/jvm mkdir -p /usr/lib/oracle-jdk9-x64-installer-unpackdir #without this, an error is displayed if the folder doesn't exist: mkdir -p /usr/lib/mozilla/plugins ############# . /usr/share/debconf/confmodule fp_exit_with_error() { echo $1 echo "Oracle JDK 9 is NOT installed." db_fset oracle-java9-installer/local seen false exit 1 } OLDDIR=/usr/lib/oracle-jdk9-x64-installer-unpackdir NEWDIR=/var/cache/oracle-jdk9-x64-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 -----------------------------------05/11/2013 ORACLE_DIR=/var/cache/oracle-jdk9-x64-installer cd $ORACLE_DIR tar xzf $FILENAME || fp_exit_with_error "cannot unpack jdk9" # FIN Lliurex -------------------------------05/11/2013 # Copy JDK to the right dir mv $J_DIR java-9-x64-oracle rm -rf /usr/lib/jvm/java-9-x64-oracle cp -rf java-9-x64-oracle /usr/lib/jvm/ # There's no javaws on arm if [ ! $arch = "arm" ]; then # Install javaws-wrapper.sh mv $J_INSTALL_DIR/bin/javaws $J_INSTALL_DIR/bin/javaws.real install -m 755 javaws-wrapper.sh $J_INSTALL_DIR/bin/javaws fi # Install jar.binfmt install -m 755 jar.binfmt $J_INSTALL_DIR/lib/jar.binfmt # Install OpenJDK's font config install -m 755 fontconfig.Ubuntu.properties $J_INSTALL_DIR/lib/ # Clean up rm -rf java-9-x64-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-java9-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)) #create .java-9-x64-oracle.jinfo file header: if [ -e /usr/lib/jvm/.java-9-x64-oracle.jinfo ]; then rm -f /usr/lib/jvm/.java-9-x64-oracle.jinfo fi echo "name=java-9-x64-oracle alias=java-9-x64-oracle priority=$LATEST section=non-free " > /usr/lib/jvm/.java-9-x64-oracle.jinfo #link JDK files 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 [ -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then if [ ! $arch = "arm" ]; then update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/bin/$name $LATEST --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-9-x64-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 $LATEST --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-9-x64-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/bin/$name $LATEST [ ! $name = "javaws.real" ] && echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-9-x64-oracle.jinfo fi fi done #link JDK not in /bin [ -f $J_INSTALL_DIR/lib/jexec ] && update-alternatives --install /usr/bin/jexec jexec $J_INSTALL_DIR/lib/jexec $LATEST --slave /usr/share/binfmts/jar jexec-binfmt $J_INSTALL_DIR/lib/jar.binfmt && echo "jdk jexec $J_INSTALL_DIR/lib/jexec" >> /usr/lib/jvm/.java-9-x64-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 $LATEST --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-9-x64-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 $LATEST --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-9-x64-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 $LATEST echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-9-x64-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-jdk9.desktop echo "NoDisplay=true" >> /usr/share/applications/JB-jvisualvm-jdk9.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-9-x64-oracle/lib/security mv cacerts cacerts.original ln -s /etc/ssl/certs/java/cacerts . fi # 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-java9 --import jar || true fi echo "Oracle JDK 9 installed" # Install Firefox (and compatible) plugin. $arch will be empty for unknown platform # No plugin for arm architecture yet [ -f $J_INSTALL_DIR/lib/$arch/libnpjp2.so ] && \ update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so $J_INSTALL_DIR/lib/$arch/libnpjp2.so $LATEST && \ echo "plugin mozilla-javaplugin.so $J_INSTALL_DIR/lib/$arch/libnpjp2.so" >> /usr/lib/jvm/.java-9-x64-oracle.jinfo && \ echo "Oracle Java 9 browser plugin installed" #DEBHELPER# exit 0 # vim: ts=2 sw=2