#!/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 2012 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 . /usr/share/debconf/confmodule ### Variables VER='0.7' # Folders J_INSTALL_DIR=/usr/lib/jvm/java-6-oracle OLDDIR=/usr/lib/oracle-jdk6-installer-unpackdir NEWDIR=/var/cache/oracle-jdk6-installer # Must be modified for each release JAVA_VERSION=6u45 J_DIR=jdk1.6.0_45 # Filenames and checksums case $(dpkg --print-architecture) in 'i386'|'i586'|'i686') arch=i386; dld=i586 # Must be modified for each release SHA256SUM_TGZ="d53b5a2518d80e1d95565f0adda54eee229dc5f4a1d1a3c2f7bf5045b168a357" ;; 'amd64') arch=amd64; dld=x64 # Must be modified for each release SHA256SUM_TGZ="6b493aeab16c940cae9e3d07ad2a5c5684fb49cf06c5d44c400c7993db0d12e8" ;; *) echo "Please report to author unsupported platform '`uname -m`'."; echo "Proceeding without web browser plugin support"; arch=''; esac FILENAME=jdk-${JAVA_VERSION}-linux-${dld}.bin for JAVA_VERSION_OLD in `seq 1 69`; do #must be modified for each release ("1 39" for 6u40; "1 40" for 6u41, etc) FILENAMES_OLD="jdk-6u${JAVA_VERSION_OLD}-linux-${dld}.bin $FILENAMES_OLD" done # Must be modified for each release!!! PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/6u45-b06/$FILENAME ### Functions fp_exit_with_error() { echo $1 echo "Oracle JDK 6 is NOT installed." db_fset oracle-java6-installer/local seen false exit 1 } fp_download_and_unpack() { cd /var/cache/oracle-jdk6-installer db_get oracle-java6-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 \ ) 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 # 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 = 2" >> wgetrc # downloading jdk6 echo "Downloading Oracle Java 6..." WGETRC=wgetrc wget --continue --no-check-certificate -O $FILENAME --header "Cookie: gpw_e24=h" $PARTNER_URL \ || fp_exit_with_error "download failed" echo "Download done." fi # end if local file # Removing outdated cached downloads echo "Removing outdated cached downloads..." rm -vf $FILENAMES_OLD # Verify SHA256 checksum of (copied or downloaded) bin rm -rf jdk*/ echo "$SHA256SUM_TGZ $FILENAME" | sha256sum -c > /dev/null 2>&1 \ || fp_exit_with_error "sha256sum mismatch $FILENAME" # Unpacking and checking the archive chmod +x $FILENAME ./$FILENAME -noregister || fp_exit_with_error "cannot unpack jdk6" } 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 } ### Main # Create dirs mkdir -p /var/cache/oracle-jdk6-installer /usr/lib/jvm /usr/lib/oracle-jdk6-installer-unpackdir # Without this, an error is displayed if the folder doesn't exist: mkdir -p /usr/lib/mozilla/plugins/ # Lliurex -----------------------------------05/11/2013 #Comentar descarga y copiar desde directorio #fp_download_and_unpack ORACLE_DIR=/var/cache/oracle-jdk6-installer echo "Installing from local file $ORACLE_DIR/$FILENAME" cp -f -p "$ORACLE_DIR"/$FILENAME ${FILENAME}_TEMP mv -f ${FILENAME}_TEMP $FILENAME cd $ORACLE_DIR chmod +x $FILENAME ./$FILENAME -noregister # FIN Lliurex -------------------------------05/11/2013 # Copy JDK to the right dir mv $J_DIR java-6-oracle rm -rf /usr/lib/jvm/java-6-oracle cp -rf java-6-oracle /usr/lib/jvm/ # 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 # Install jar.binfmt install -m 755 jar.binfmt $J_INSTALL_DIR/jre/lib/jar.binfmt # Clean up rm -Rf java-6-oracle # To add when an older version exists: # safe_move jdk-6u36-linux-x64.tar.gz #must be modified for each release # safe_move jdk-6u36-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-java6-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-6-oracle.jinfo file header: if [ -e /usr/lib/jvm/.java-6-oracle.jinfo ]; then rm -f /usr/lib/jvm/.java-6-oracle.jinfo fi echo "name=java-6-oracle alias=java-6-oracle priority=$LATEST section=non-free " > /usr/lib/jvm/.java-6-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 update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $LATEST \ --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-6-oracle.jinfo 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 $LATEST [ ! $name = "javaws.real" ] && echo "jre $name $J_INSTALL_DIR/jre/bin/$name" >> /usr/lib/jvm/.java-6-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 $LATEST \ --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-6-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 # Handle any legacy uncompressed pages name=`basename $f .1`; fi 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 \ --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-6-oracle.jinfo 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-6-oracle.jinfo fi fi done fi # Register binfmt; ignore errors, the alternative may already be registered by another JRE. which update-binfmts >/dev/null && [ -r /usr/share/binfmts/jar ] && \ update-binfmts --package oracle-java6 --import jar || true echo "Oracle JDK 6 installed" # Install Firefox (and compatible) plugin. $arch will be empty for unknown platform [ -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 $LATEST && \ echo "plugin mozilla-javaplugin.so $J_INSTALL_DIR/jre/lib/$arch/libnpjp2.so" >> /usr/lib/jvm/.java-6-oracle.jinfo echo "Oracle JRE 6 browser plugin installed" #DEBHELPER# exit 0 # vim: ts=2 sw=2