script for updating Java

Hisham <[email protected]>
Newsgroups gmane.linux.distributions.gobo.general
Message-ID <CAJpkDYcjhmoBynADymDTyUiii_O7seyK8Shc1XzkUQK5dGSnWw@mail.gmail.com>
Hello,

Here's a script that updates Java doing the necessary magic to
download from the Oracle website and installs it into
/Programs/Oracle-JDK.

I've been using it for a few versions and it didn't break, so I
decided to improve it a bit implementing version auto-detection.

Hope it's useful! Enjoy!

-- Hisham

_______________________________________________
gobolinux-users mailing list
[email protected]
http://lists.gobolinux.org/mailman/listinfo/gobolinux-users
update_java.sh (application/x-sh, 2.4 KB)
#!/bin/bash

[ "$1" == "--help" ] && {
   echo
   echo "Usage: sudo $0 [<version> <build>]"
   echo
   echo "Example: sudo $0 7u45 b18"
   echo
   echo "Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html"
   echo "to see the latest version and build."
   echo "When run with no arguments, it will try to go to that URL automatically"
   echo "and figure out the version and build automatically."
   echo
   exit 0
}

version="$1"
build="$2"

#[ "$build" ] || {
#   echo "Usage: sudo $0 <version> <build>"
#   echo "Example: sudo $0 7u45 b18"
#   echo "Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html"
#   echo "to see the latest version and build."
#   exit 1
#}

[ "$UID" != "0" ] && {
   echo "Please run this with sudo."
   exit 1
}

[ "$build" ] || {
   mkdir -p /tmp/update_java
   cd /tmp/update_java
   rm *
   wget http://www.oracle.com/technetwork/java/javase/downloads/index.html
   version=`cat /tmp/update_java/index.html | tr '<' '\n' | grep "Java SE [0-9]u[0-9][0-9]" | sed 's,.*Java SE \(.u..\).*,\1,g' | sort -r | head -n 1`
   major=${version:0:1}
   dllink=`cat /tmp/update_java/index.html | tr '"' '\n' | sed -n 's,.*\(technetwork/java/javase/downloads/jdk'$major'-downloads-[0-9]*.html\).*,\1,gp' | head -n 1`
   wget http://www.oracle.com/$dllink
   dlpage=$(basename "$dllink")
   build=`cat $dlpage | grep "java/jdk/$version-.*/jdk-$version-linux-i586.tar.gz" | sed "s,.*$version-\(.*\)/jdk-$version-linux.*,\1,g"`
   
   if [ "${version:1:1}" != "u" -o "${build:0:1}" != "b" ]
   then
      echo
      echo "Error: failed auto-detecting version and build."
      echo "You'll need to provide them explicitly."
      echo "Run '$0 --help' for details."
      exit 1
   fi   
}

mkdir -p ~/java-$version-$build
cd ~/java-$version-$build

url="http://download.oracle.com/otn-pub/java/jdk/$version-$build/jdk-$version-linux-i586.tar.gz"

targz="jdk-$version-linux-i586.tar.gz"

dlurl="http://www.oracle.com/$dllink"
dlcookie=$(echo $dlurl | sed 's,/,%2F,g')

wget --no-check-certificate --no-cookies \
   --header "Cookie: gpw_e24=$dlcookie;oraclelicense=accept-securebackup-cookie;s_cc=true;s_nr=`date +'%s803'`;s_sq=%5B%5BB%5D%5D" \
   --referer "$dlurl" \
   -c "$url" -O "$targz"

tar zxvpf "$targz"

gobover="${version}_${build}_bin"

PrepareProgram --tree Oracle-JDK "$gobover"

mv jdk*/* /Programs/Oracle-JDK/$gobover

SymlinkProgram -c overwrite Oracle-JDK "$gobover"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.