====== 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