#!/bin/sh

cd /System/Library/Frameworks/JavaVM.framework/Versions

CURJDK="`readlink CurrentJDK`"
echo Current JDK version: $CURJDK

if [ "$1" == "" ]; then
echo Installed versions:
ls
exit
fi

VERFOUND=`ls | grep $1 | head -n 1`

if [ "$VERFOUND" != "$1" ]; then

   VERSIONS=(`ls -r | grep 1.4`)
   len=${#VERSIONS[*]}

   if [ $len -gt 0 ]; then
     echo You must now enter your Mac OS X password to change the JDK.
     sudo ln -fhsv ${VERSIONS[O]} CurrentJDK
     echo Now Current JDK version is: ${VERSIONS[0]}
     exit 
   else
     BASE="`basename $0`"
     echo Error: Could not change JDK-- version $1 not installed!
     echo Run $BASE without arguments to see a list of installed versions.
     exit 127
   fi
   exit 
fi

echo You must now enter your Mac OS X password to change the JDK.
sudo ln -fhsv $1 CurrentJDK
echo Now Current JDK version is: $1
