#!/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=x86; SHA256SUM_TGZ="09ef872d01e1714e22a93f7f03f49d27a489d2d4e0c4c61a612c339bc7846fc7" #must be modified for each release ;; 'amd64' ) arch=amd64; dld=x64; SHA256SUM_TGZ="66fc4676719bd0e64ff4fe7bd8417d083d634c95da077156c98dbd264c7cb0d5" #must be modified for each release ;; arm* ) arch=arm if [ `uname -m` = "armv7l" ] || [ `uname -m` = "armv6l" ]; then if [ -x /usr/bin/readelf ] ; then HARDFLOAT=`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args` if [ -z "$HARDFLOAT" ]; then # Softfloat #dld='arm32-sflt' #SHA256SUM_TGZ="d7a6296bd0cf95cd70a53d4bd2475f7910aadf9e04167979224e7004f919d95f" #must be modified for each release echo "Oracle JDK9 only supports ARM v6/v7 hardfloat and ARM64." arch='' else # Hardfloat dld='arm32-vfp-hflt' SHA256SUM_TGZ="53f7d591090f4e978370797e4e94ab8b4946b2bb385f8e25752fb7735490a941" #must be modified for each release fi fi elif [ `uname -m` = "armv8l" ] || [ `uname -m` = "arm64" ] || [ `uname -m` = "aarch64" ]; then dld='arm64-vfp-hflt' SHA256SUM_TGZ="cf62334c5f862bb0dd9bed53da8cc6a5460cc8566ef192b7445670d6594061ac" #must be modified for each release else echo "Oracle JDK9 only supports ARM v6/v7 hardfloat and ARM64." arch='' fi ;; * ) echo "Please report to author unsupported platform '`uname -m`'."; echo "Proceeding without web browser plugin support"; arch=''; esac ########Variables if [ ! $arch = "arm" ]; then if [ ! $arch = "amd64" ]; then JAVA_VERSION_MAJOR=9 # JAVA_VERSION_MINOR=140 #must be modified for each release JAVA_VERSION_DATE="04_nov_2015" #no longer needed with b95 J_DIR=jdk-9 #must be modified for each release FILENAME=jdk-${JAVA_VERSION_MAJOR}-ea+${JAVA_VERSION_MINOR}_linux-${dld}_bin.tar.gz # dk-9-ea+109_linux-x86_bin.tar.gz else JAVA_VERSION_MAJOR=9.0.1 # JAVA_VERSION_MINOR=11 #must be modified for each release #JAVA_VERSION_DATE="dic_2017" #no longer needed with b95 J_DIR=jdk-${JAVA_VERSION_MAJOR} #must be modified for each release FILENAME=jdk-9-linux-x64.tar.gz # dk-9-ea+109_linux-x86_bin.tar.gz fi PARTNER_URL=http://www.java.net/download/java/jdk${JAVA_VERSION_MAJOR}/archive/${JAVA_VERSION_MINOR}/binaries/$FILENAME else JAVA_VERSION_MAJOR=9 # JAVA_VERSION_MINOR=141 #must be modified for each release JAVA_VERSION_DATE="04_nov_2015" #no longer needed with b95 J_DIR=jdk-9 #must be modified for each release FILENAME=jdk-${JAVA_VERSION_MAJOR}-ea+${JAVA_VERSION_MINOR}_linux-${dld}_bin.tar.gz # jdk-9-ea+109_linux-arm64-vfp-hflt_bin.tar.gz PARTNER_URL=http://www.java.net/download/java/jdk${JAVA_VERSION_MAJOR}/archive/${JAVA_VERSION_MINOR}/binaries/$FILENAME fi for JAVA_VERSION_OLD1 in `seq 48 139`; do #must be modified for each release FILENAMES_OLD1="jdk-${JAVA_VERSION_MAJOR}-ea-bin-b${JAVA_VERSION_OLD1}-linux*.tar.gz $FILENAMES_OLD1" done for JAVA_VERSION_OLD2 in `seq 48 139`; do #must be modified for each release FILENAMES_OLD2="jdk-${JAVA_VERSION_MAJOR}-ea+${JAVA_VERSION_OLD2}_linux*.tar.gz $FILENAMES_OLD2" done J_INSTALL_DIR=/usr/lib/jvm/java-9-oracle ########Create dirs mkdir -p /var/cache/oracle-jdk9-installer mkdir -p /usr/lib/jvm mkdir -p /usr/lib/oracle-jdk9-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 9 is NOT installed." db_fset oracle-java9-installer/local seen false exit 1 } fp_download_and_unpack() { cd /var/cache/oracle-jdk9-installer db_get oracle-java9-installer/local if [ -d "$RET" -a -f "$RET"/$FILENAME ]; then echo "Installing from local file $RET/$FILENAME" cp -f -p "$RET"/$FILENAME ${FILENAME}_TEMP mv -f ${FILENAME}_TEMP $FILENAME else # no local file # use apt proxy APT_PROXIES=$(apt-config shell \ http_proxy Acquire::http::Proxy \ https_proxy Acquire::https::Proxy \ ftp_proxy Acquire::ftp::Proxy \ dl_direct Acquire::http::Proxy::download.oracle.com \ dl_direct Acquire::http::Proxy::*.java.net \ ) if [ -n "$APT_PROXIES" ]; then eval export $APT_PROXIES fi if [ "$dl_direct" = "DIRECT" ]; then unset http_proxy unset https_proxy unset ftp_proxy fi # if /var/cache/oracle-jdk9-installer/wgetrc exists, use it for downloading java if [ -f /var/cache/oracle-jdk9-installer/wgetrc ]; then # downloading jdk9 echo "Using wget settings from /var/cache/oracle-jdk9-installer/wgetrc" echo "Downloading Oracle Java 9..." WGETRC=wgetrc wget --continue --no-check-certificate -O $FILENAME --header "Cookie: oraclelicense=a" $PARTNER_URL \ || fp_exit_with_error "download failed" echo "Download done." #if it's not, use the settings below (which also creates /var/cache/oracle-jdk9-installer/wgetrc) else # setting wget options :> wgetrc echo "noclobber = off" >> wgetrc echo "dir_prefix = ." >> wgetrc echo "dirstruct = off" >> wgetrc echo "verbose = on" >> wgetrc echo "progress = dot:mega" >> wgetrc echo "tries = 5" >> wgetrc # downloading jdk9 echo "No /var/cache/oracle-jdk9-installer/wgetrc file found." echo "Creating /var/cache/oracle-jdk9-installer/wgetrc and" echo "using default oracle-java9-installer wgetrc settings for it." echo "Downloading Oracle Java 9..." WGETRC=wgetrc wget --continue --no-check-certificate -O $FILENAME --header "Cookie: oraclelicense=a" $PARTNER_URL \ || fp_exit_with_error "download failed" echo "Download done." fi fi # end if local file # Removing outdated cached downloads echo "Removing outdated cached downloads..." rm -vf $FILENAMES_OLD rm -vf $FILENAMES_OLD1 rm -vf $FILENAMES_OLD2 rm -vf $FILENAMES_OLD_N rm -vf $FILENAMES_OLD_NA # verify SHA256 checksum of (copied or downloaded) tarball rm -rf jdk*/ echo "$SHA256SUM_TGZ $FILENAME" | sha256sum -c > /dev/null 2>&1 \ || fp_exit_with_error "sha256sum mismatch $FILENAME" # unpacking and checking the plugin tar xzf $FILENAME || fp_exit_with_error "cannot unpack jdk9" } OLDDIR=/usr/lib/oracle-jdk9-installer-unpackdir NEWDIR=/var/cache/oracle-jdk9-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 # #fp_download_and_unpack ORACLE_DIR=/var/cache/oracle-jdk9-installer rm -f ${FILENAME} cd $ORACLE_DIR tar xzf $FILENAME || fp_exit_with_error "cannot unpack jdk9" # END LLIUREX # Copy JDK to the right dir mv $J_DIR java-9-oracle rm -rf /usr/lib/jvm/java-9-oracle cp -rf java-9-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 # Fix jexec not being executable in latest version(s?) chmod +x $J_INSTALL_DIR/lib/jexec # 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-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)) PRIORITY=1091 #create .java-9-oracle.jinfo file header: if [ -e /usr/lib/jvm/.java-9-oracle.jinfo ]; then rm -f /usr/lib/jvm/.java-9-oracle.jinfo fi echo "name=java-9-oracle alias=java-9-oracle priority=$PRIORITY section=non-free " > /usr/lib/jvm/.java-9-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 $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-9-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-9-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 $PRIORITY [ ! $name = "javaws.real" ] && echo "jdk $name $J_INSTALL_DIR/bin/$name" >> /usr/lib/jvm/.java-9-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 $PRIORITY --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-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-9-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-9-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-9-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 ] && [ -e /usr/lib/jvm/java-9-oracle/lib/security/cacerts ]; then cd /usr/lib/jvm/java-9-oracle/lib/security mv cacerts cacerts.original ln -s /etc/ssl/certs/java/cacerts . fi # Place all config files in /etc so they are not overwritten on upgrade mkdir -p /etc/java-9-oracle/conf/security mkdir -p /etc/java-9-oracle/conf/management # A. Default /usr/lib/jvm/java-9-oracle/conf folder for configfile in logging.properties net.properties sound.properties do if [ ! -e /etc/java-9-oracle/conf/"$configfile" ] && [ -e /usr/lib/jvm/java-9-oracle/conf/"$configfile" ]; then mv /usr/lib/jvm/java-9-oracle/conf/"$configfile" /etc/java-9-oracle/conf/ else rm -f /usr/lib/jvm/java-9-oracle/conf/"$configfile" fi done for configfile in logging.properties net.properties sound.properties do if [ ! -e /usr/lib/jvm/java-9-oracle/conf/"$configfile" ] && [ -e /etc/java-9-oracle/conf/"$configfile" ]; then ln -s /etc/java-9-oracle/conf/"$configfile" /usr/lib/jvm/java-9-oracle/conf/ fi done # B. /usr/lib/jvm/java-9-oracle/conf/management folder (use snmp.acl and jmxremote.password instead of the .template # files, since those are just placeholders) for configfile in jmxremote.access jmxremote.password management.properties snmp.acl do if [ ! -e /etc/java-9-oracle/conf/management/"$configfile" ] && [ -e /usr/lib/jvm/java-9-oracle/conf/management/"$configfile" ]; then mv /usr/lib/jvm/java-9-oracle/conf/management/"$configfile" /etc/java-9-oracle/conf/management/ else rm -f /usr/lib/jvm/java-9-oracle/conf/management/"$configfile" fi done for configfile in jmxremote.access jmxremote.password management.properties snmp.acl do if [ ! -e /usr/lib/jvm/java-9-oracle/conf/management/"$configfile" ] && [ -e /etc/java-9-oracle/conf/management/"$configfile" ]; then ln -s /etc/java-9-oracle/conf/management/"$configfile" /usr/lib/jvm/java-9-oracle/conf/management/ fi done # B. /usr/lib/jvm/java-9-oracle/conf/security folder for configfile in java.policy java.security javaws.policy do if [ ! -e /etc/java-9-oracle/conf/security/"$configfile" ] && [ -e /usr/lib/jvm/java-9-oracle/conf/security/"$configfile" ]; then mv /usr/lib/jvm/java-9-oracle/conf/security/"$configfile" /etc/java-9-oracle/conf/security/ else rm -f /usr/lib/jvm/java-9-oracle/conf/security/"$configfile" fi done for configfile in java.policy java.security javaws.policy do if [ ! -e /usr/lib/jvm/java-9-oracle/conf/security/"$configfile" ] && [ -e /etc/java-9-oracle/conf/security/"$configfile" ]; then ln -s /etc/java-9-oracle/conf/security/"$configfile" /usr/lib/jvm/java-9-oracle/conf/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-java9 --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/lib/$arch/libnpjp2.so ] && \ update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so $J_INSTALL_DIR/lib/$arch/libnpjp2.so $PRIORITY && \ echo "plugin mozilla-javaplugin.so $J_INSTALL_DIR/lib/$arch/libnpjp2.so" >> /usr/lib/jvm/.java-9-oracle.jinfo && \ echo "Oracle Java 9 browser plugin installed" echo "Oracle JDK 9 installed" echo "" echo "#####Important########" echo "To set Oracle JDK9 as default, install the \"oracle-java9-set-default\" package." echo "E.g.: sudo apt install oracle-java9-set-default." #DEBHELPER# exit 0 # vim: ts=2 sw=2