Benutzer-Werkzeuge

Webseiten-Werkzeuge


java-update-script

Java-Update-Script

Basiernd auf http://webupd8.googlecode.com/files/update-java habe ich ein modifiziertes Scritp erstellt, welches auf der Commandline läuft und aus Dateien auch Java aspackt.

Das Script kann mit der zu installierenden Datei al Parameter aufgerufen werden. Ohne Parameter kann man eine Datei auswählen.

Installation

wget -O /usr/local/bin/update-java "https://wiki.mhcsoftware.de/_export/code/java-update-script?codeblock=1"
chmod +x /usr/local/bin/update-java

Script

#!/bin/bash
#update-java VERSION 0.2beta
#Linux Java update script: Remove old versions, point default at latest version

#Copyright 2010, Bruce Ingalls GPL 3 Affero see http://www.gnu.org/ for details
#Downloads & discussion at http://www.webupd8.org/
#Contact bingalls at users dot sf dot net for licensing & additional help
#Currently supports Ubuntu, only. Likely less useful for RPM based Linux distros.
#Currently supports only full java jdk, not jre.
#Note that update-alternatives by default misses many java tools, such as 'jar'
#Known bugs:
#  Cancelling takes half a minute.
#  Sun does not install JRE in a standard location
#  Gkmsgs cannot handle spaces
#  Does not check for Japanese environment & man pages

NP=$#

#BEGIN User Customizations
SUN_ROOT="/usr/local"
UBUNTU_ROOT="/usr/lib/jvm"
OPT_ROOT="/opt"

#i18n. Change for non-english

INSTALL_MESSAGE="Installing:"
ASK_FOR_NEW_FILE="Do you want to install new Java binaries\nfrom file in $UBUNTU_ROOT?"
DELETE_CONFIRM_MSG="OK to delete these Java directories?"
DELETE_JAVA_MSG="Choose Java versions to DELETE if you want to."
SELECT_JAVA_MSG="Choose Java version to update to"

#END User Customizations

#If locate is active for this system, then we must add the new install.
#Running in background to avoid waiting, but might not progress adequately, before its use, below

function install_file() {
	F=$1
	dialog --infobox "$INSTALL_MESSAGE\n$F" 7 70
	cd $UBUNTU_ROOT
	case $(file -b $F | cut -d " " -f 1) in
	data)
		chmod +x $F
		$F
		;;
	gzip)
		tar xfz $F >/dev/null
		;;
	tar)
		tar xf $F >/dev/null
		;;
	*)
		echo "Fiel format not recognized"
		exit 0
		;;
	esac
	if [ $? -gt 0 ]; then
		echo "Install failed"
		exit 0
	fi
}



_temp="/tmp/answer.$$"

if [ ! -z /var/lib/mlocate/mlocate.db ]; then
    updatedb&
fi

which dialog > /dev/null;
if [ $? -gt 0 ]; then
	echo "Please install 'dialog'."
	exit 0
fi

mkdir -p $UBUNTU_ROOT

if [ $NP -eq 1 ]; then
	if [ -f $1 ]; then
		install_file $1
	fi
else
	dialog --yesno "$ASK_FOR_NEW_FILE" 6 50
	if [ $? -eq 0 ]; then
		dialog --fselect "$HOME" 20 70 2>$_temp
		F=`cat $_temp | sed 's/\"//g'`
		install_file $F
	fi
fi


#load current java link
jdefault=`ls -dog /etc/alternatives/java 2>/dev/null | awk '{print $8}' | sed 's|/bin/java||'`

#Populate the dialog box with located jre directories
JAVADIRS=$(
    ls -1d $UBUNTU_ROOT/java-* 2>/dev/null
    ls -1d $UBUNTU_ROOT/jdk* 2>/dev/null
    ls -1d $OPT_ROOT/java-* 2>/dev/null
    ls -1d $OPT_ROOT/jdk* 2>/dev/null
    ls -1d $SUN_ROOT/jdk* 2>/dev/null
    locate bin/java_vm | grep jre1. | sed 's|/bin/java_vm||'  ||
    beagle-query bin/java_vm | grep jre1. | sed 's|/bin/java_vm||' | sed 's|file://||' 2>/dev/null
    )

dialog --checklist "$DELETE_JAVA_MSG" 20 70 17 \
$( for j in ${JAVADIRS[*]}; do
	echo $j _ off
done ) 2>$_temp

if [ $? -eq 1 ]; then
	exit 0
fi

DELDIR=`cat $_temp | sed 's/\"//g'`

if [ ${#DELDIR} -gt 0 ]; then
    dialog --yesno "$DELETE_CONFIRM_MSG" 5 50
    if [ $? -eq 0 ]; then
        DELETE=`echo ${DELDIR[*]}|tr '|' ' '`
        `"rm -fr $DELETE"`
        for j in ${DELDIR[*]}; do
            update-alternatives --remove java $j/bin/java
            update-alternatives --remove java_vm $j/bin/java_vm
            update-alternatives --remove javaws $j/bin/javaws
            update-alternatives --remove jcontrol $j/bin/jcontrol
            update-alternatives --remove keytool $j/bin/keytool
            update-alternatives --remove pack200 $j/bin/pack200
            update-alternatives --remove policytool $j/bin/policytool
            update-alternatives --remove rmid $j/bin/rmid
            update-alternatives --remove rmiregistry $j/bin/rmiregistry
            update-alternatives --remove servertool $j/bin/servertool
            update-alternatives --remove tnameserv $j/bin/tnameserv
            update-alternatives --remove unpack200 $j/bin/unpack200
        done
    fi
fi

#--menu         <text> <height> <width> <menu height> <tag1> <item1>...
dialog --menu "$SELECT_JAVA_MSG" 20 70 17 \
$( for j in ${JAVADIRS[*]}; do
	echo $j _
done ) 2>$_temp

if [ $? -eq 1 ]; then
	exit 0
fi

#Grab the new Java link from the radio dialog box 
NEWDIR=`cat $_temp | sed 's/\"//g'`

if [ $? -gt 0 ]; then exit 2; fi                #cancel clicked
if [[ $NEWDIR == '' ]]; then exit 3; fi   #OK clicked, but no selection

#Increment highest version by 1. DEPENDS on update-alternative msg formatting (in English)!
#Also assumes all Java helper programs (javaws, jcontrol, etc) at same version as java
LATEST=$((`update-alternatives --query java|grep Priority:|awk '{print $2}'|sort -n|tail -1`+1));

[ -f $NEWDIR/bin/java ]        && update-alternatives --install /usr/bin/java        java        $NEWDIR/bin/java $LATEST        --slave /usr/share/man/man1/java.1.gz java.1.gz $NEWDIR/man/man1/java.1.gz
[ -f $NEWDIR/bin/java_vm ]     && update-alternatives --install /usr/bin/java_vm     java_vm     $NEWDIR/jre/bin/java_vm $LATEST
[ -f $NEWDIR/bin/javaws ]      && update-alternatives --install /usr/bin/javaws      javaws      $NEWDIR/bin/javaws $LATEST      --slave /usr/share/man/man1/javaws.1 javaws.1 $NEWDIR/man/man1/javaws.1
[ -f $NEWDIR/bin/jcontrol ]    && update-alternatives --install /usr/bin/jcontrol    jcontrol    $NEWDIR/bin/jcontrol $LATEST
[ -f $NEWDIR/bin/keytool ]     && update-alternatives --install /usr/bin/keytool     keytool     $NEWDIR/bin/keytool $LATEST     --slave /usr/share/man/man1/keytool.1 keytool.1 $NEWDIR/man/man1/keytool.1
[ -f $NEWDIR/bin/pack200 ]     && update-alternatives --install /usr/bin/pack200     pack200     $NEWDIR/bin/pack200 $LATEST     --slave /usr/share/man/man1/pack200.1 pack200.1 $NEWDIR/man/man1/pack200.1
[ -f $NEWDIR/bin/policytool ]  && update-alternatives --install /usr/bin/policytool  policytool  $NEWDIR/bin/policytool $LATEST  --slave /usr/share/man/man1/policytool.1 policytool.1 $NEWDIR/man/man1/policytool.1
[ -f $NEWDIR/bin/rmid ]        && update-alternatives --install /usr/bin/rmid        rmid        $NEWDIR/bin/rmid $LATEST        --slave /usr/share/man/man1/rmid.1 rmid.1 $NEWDIR/man/man1/rmid.1
[ -f $NEWDIR/bin/rmiregistry ] && update-alternatives --install /usr/bin/rmiregistry rmiregistry $NEWDIR/bin/rmiregistry $LATEST --slave /usr/share/man/man1/rmiregistry.1 rmiregistry.1 $NEWDIR/man/man1/rmiregistry.1
[ -f $NEWDIR/bin/servertool ]  && update-alternatives --install /usr/bin/servertool  servertool  $NEWDIR/bin/servertool $LATEST  --slave /usr/share/man/man1/servertool.1 servertool.1 $NEWDIR/man/man1/servertool.1
[ -f $NEWDIR/bin/tnameserv ]   && update-alternatives --install /usr/bin/tnameserv   tnameserv   $NEWDIR/bin/tnameserv $LATEST   --slave /usr/share/man/man1/tnameserv.1 tnameserv.1 $NEWDIR/man/man1/tnameserv.1
[ -f $NEWDIR/bin/unpack200 ]   && update-alternatives --install /usr/bin/unpack200   unpack200   $NEWDIR/bin/unpack200 $LATEST   --slave /usr/share/man/man1/unpack200.1 unpack200.1 $NEWDIR/man/man1/unpack200.1

PLUGIN=`find $NEWDIR -name "libnpjp2.so"`
[ -f $PLUGIN ] && update-alternatives --install /usr/lib/mozilla/plugins/libnpjp2.so libnpjp2.so $PLUGIN $LATEST

#update-alternatives --remove libnpjp2.so $NEWDIR/jre/lib/i386/libnpjp2.so

java-update-script.txt · Zuletzt geändert: 2017/03/17 11:37 von 127.0.0.1