linuxman94

java setup

Nov 12th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | None | 0 0
  1. #!/bin/bash
  2. # Script to download the java binaries (if needed) and set up the java paths
  3. # Copyright 2013 Evan Anderson
  4.  
  5. javaf="jdk-6u45-linux-x64.bin"
  6. javadl="http://download.oracle.com/otn-pub/java/jdk/6u45-b06/$javaf"
  7. javav="jdk1.6.0_45"
  8. installpath="java"
  9.  
  10. function getjava() {
  11.     wget -q --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" "$javadl"
  12.     chmod +x $javaf
  13.     ./$javaf &> /dev/null
  14.     mv $javav/* .
  15.     rm -r $javav $javaf
  16. }
  17.  
  18. function checkjava() {
  19.     if [ $(javac -version 2>&1 | head -n1 | cut -f2 -d' ' | grep 1.6) ]; then
  20.         installed=1
  21.     else
  22.         installed=0
  23.     fi
  24. }
  25.  
  26. function setpath() {
  27.     export JAVA_HOME=`pwd`/$installpath/bin/
  28.     export PATH=`pwd`/$installpath/bin:$PATH
  29.     echo -e "Java paths set"
  30. }
  31.  
  32. #first check if system java is correct
  33. checkjava
  34.  
  35. if [ $installed = 1 ]; then
  36.     echo -e "System Java is the correct version"
  37.   elif [ ! -d "$installpath" ]; then
  38.     echo -e "Error: Java not found, downloading..."
  39.     mkdir $installpath; cd $installpath
  40.     getjava
  41.     setpath
  42.   elif [ "-d "$installpath"" -a "$installed = 0" ]; then
  43.     setpath
  44. fi
Advertisement
Add Comment
Please, Sign In to add comment