Page 1 of 1

How to Install Java 7 (Script Inside)

Posted: Mon Oct 08, 2012 11:15 am
by bigj231
Hello everyone,
I got tired of manually plugging commands into a terminal to install java, so I decided to make a script.
The user must input the java version and update number, as well as the architecture. You can also specify the file location for the downloaded package. It installs to /opt/java.
You can report bugs here or at my website listed in the file
Credit for the original install process goes to: http://sites.google.com/site/easylinuxtipsproject/java
I made a youtube tutorial for this as well. Check it out here and leave a like if you can. It encourages me to make more stuff.

Code: Select all

#! /bin/bash
# This script is used to automatically update JAVA version 7 to the specified
# update.
###############################################################################
# This script is made by Bigj231. Bugs, ideas, and suggestions
# can be reported on my site at:
# http://sites.google.com/site/bigj231/scripts-and-useful-stuff
# OR in this thread on the Linux Mint forums:
# http://forums.linuxmint.com/viewtopic.php?f=213&t=114316
# Credit for the original install process goes to: 
# http://sites.google.com/site/easylinuxtipsproject/java
# Credit for the idea for Opera Support goes to Meteorrock at the Linux Mint 
# Forums.
###############################################################################
# Although I haven't had any issues with this script, I'm sure somebody will 
# find a way to break something with it.
# This script is provided as-is with no warranties either expressed or implied.
#########################    USE AT YOUR OWN RISK!   ##########################
###############################################################################

# Determine Java platform
echo -n "Are you installing the [JRE] or JDK? "
read PLATFORM
if [ "x$PLATFORM" == "xJDK" ]; then
     echo "This script does not currently work for installing the JDK."
     echo "Please read the thread in the Linux Mint forums at :http://forums.linuxmint.com/viewtopic.php?f=213&t=114316"
     exit 1
fi

# Determine java version
echo -n "Which java version are you installing? "
read VER
echo -n "Which java update are you installing? "
read UPD

# Determine 64 or 32 bit java
echo -n "Which architecture are you installing? (32/64): "
read ARCH
while [ "x$ARCH" != "x32" ] && [ "x$ARCH" != "x64" ]; do
  echo "Please input valid architecture (32/64):"
  read ARCH
done


# Remove earlier java versions & pligins
echo -n "Do you want to remove the IcedTea plugin? (YES/no): "
read  ARG
if [ "x$ARG" == "xno" ]; then
     echo "IcedTea kept."
else
     sudo apt-get remove icedtea-6-plugin && sudo apt-get remove icedtea-7-plugin   
fi
echo -n "Do you want to remove previous $ARCH-bit java versions? (YES/no): "
read -e ARG
if [ "x$ARG" == "xno" ]; then
     echo "Previous $ARCH-bit java versions kept."
else
    sudo rm -r -v /opt/java/$ARCH
fi

# Remove Firefox Plugin
echo -n "Do you want to remove Firefox plugin? (YES/no): "
read -e ARG
if [ "x$ARG" == "xno" ]; then
     echo "Previous Firefox plugin kept."
else
     rm -v ~/.mozilla/plugins/libnpjp2.so
fi

# Remove Opera Plugin
echo -n "Do you want to remove Opera plugin? (YES/no): "
read -e ARG
if [ "x$ARG" == "xno" ]; then
     echo "Previous Opera plugin kept."
else
     rm -v /usr/lib/opera/plugin/libnpjp2.so
fi


# Start installing JAVA
# Get location of downloaded file
u="u" # this line is because I have no clue how to get the filename correct
# without defining another variable.

if [ "x$ARCH" = "x32" ]; then 
  echo "Input destination to downloaded java package. Defaults to ~/Downloads/jre-$VER\u$UPD-linux-i586.tar.gz: "
  read FILE
  if [ "x$FILE" == "x" ]; then
    FILE=~/Downloads/jre-$VER$u$UPD-linux-i586.tar.gz
  fi
  while [ ! -f $FILE ]; do
    echo "Please input a valid filename: "
    read FILE
    if [ "x$FILE" == "x" ]; then
      FILE=~/Downloads/jre-$VER$u$UPD-linux-i586.tar.gz
    fi
  done
else 
  echo "Input destination to downloaded java package. Defaults to ~/Downloads/jre-$VER$u$UPD-linux-x64.tar.gz: "
  read FILE
  if [ "x$FILE" == "x" ]; then
    FILE=~/Downloads/jre-$VER$u$UPD-linux-x64.tar.gz
  fi
  while [ ! -f $FILE ]; do
    echo "Please input a valid filename: "
    read FILE
    if [ "x$FILE" == "x" ]; then
      FILE=~/Downloads/jre-$VER$u$UPD-linux-x64.tar.gz
    fi
  done
fi

# Extract the files
echo "Where would you like to extract the files? Defaults to ~/Downloads :"
read PATH
if [ "x$PATH" == "x" ]; then
  PATH=~/Downloads
fi
while [ ! -d $PATH ]; do
  echo "Please Input a valid directory:"
  read PATH
  if [ "x$PATH" == "x" ]; then
    PATH=~/Downloads
  fi
done
cd "$PATH"
/usr/bin/sudo /bin/tar -xzvf "$FILE"

# move the files to /opt/java
/usr/bin/sudo /bin/mkdir -p -v /opt/java/$ARCH
/usr/bin/sudo mv -v ~/Downloads/jre1.$VER.0_$UPD /opt/java/$ARCH

#  Inform the system and make the new JRE the default 
/usr/bin/sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/$ARCH/jre1.$VER.0_$UPD/bin/java" 1
/usr/bin/sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/$ARCH/jre1.$VER.0_$UPD/bin/java" 1
/usr/bin/sudo update-alternatives --set java /opt/java/$ARCH/jre1.$VER.0_$UPD/bin/java

# Install Firefox plugin
echo "Do you want to install the Firefox Plugin? (YES/no) "
read  ARG
if [ "x$ARG" == "xno" ]; then
     echo "Firefox plugin not installed."
else
  /bin/mkdir -v ~/.mozilla/plugins
  if [ "x$ARCH" = "x32" ]; then  
    /bin/ln -s /opt/java/32/jre1.$VER.0_$UPD/lib/i386/libnpjp2.so ~/.mozilla/plugins/
  else
    /bin/ln -s /opt/java/64/jre1.$VER.0_$UPD/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
  fi
  echo " Firefox plugin installed."
fi

# Install Opera plugin
echo "Do you want to install the Opera Plugin? (YES/no) "
read  ARG
if [ "x$ARG" == "xno" ]; then
     echo "Opera plugin not installed."
else
  /bin/mkdir -v /usr/lib/opera/plugin/
  if [ "x$ARCH" = "x32" ]; then  
    /bin/ln -s /opt/java/32/jre1.$VER.0_$UPD/lib/i386/libnpjp2.so /usr/lib/opera/plugin
  else
    /bin/ln -s /opt/java/64/jre1.$VER.0_$UPD/lib/amd64/libnpjp2.so /usr/lib/opera/plugin
  fi
  echo "Opera plugin installed."
fi

# Open JAVA Control panel
echo "Do you want to open the JAVA control panel? (yes/NO) "
read  ARG
if [ "x$ARG" == "xyes" ]; then
     /opt/java/$ARCH/jre1.$VER.0_$UPD/bin/ControlPanel
fi

exit 0
And now for the promised chaneglog:

Code: Select all

3/31/2013:
    - Added option for JDK installation. ~ currently exits with code 1, and tells you to report back here.

2/1/2013:
     - Fixed a bug where Directories were not being created

1/21/2013:
     - Added opera plugin support.
     - Fixed a bug where directory selection would default to ~/Downloads if non-exsistent path was given.
     - Removed support for update numbers with less than 2 digits. Now 1-9 must be input as 01-09.

Re: How to Install Java 7 (Script Inside)

Posted: Mon Oct 08, 2012 1:19 pm
by sagirfahmid3
Nice, I made a similar one a while ago, but I've been too busy with homework. Good to see you took this up =)

Re: How to Install Java 7 (Script Inside)

Posted: Sat Oct 13, 2012 10:16 am
by bigj231
I've had it sitting on my hard drive for a while, and it's worked twice for me, so I decided to share it. No sense in making everyone else reinvent the wheel.

Re: How to Install Java 7 (Script Inside)

Posted: Wed Oct 24, 2012 6:17 pm
by Althorax
Script looks great, but I'm not sure what to enter at these points:

# Determine java version
echo -n "Which java version are you installing? "
echo -n "Which java update are you installing? "

Maybe inserting an example in the text would help???

I don't like the third party option and I would like to try yours. I downloaded the following file:

~/Downloads/jre-7u7-linux-x64.tar.gz

Do you think you could give me some guidance?

Thanks in advance!!!

Re: How to Install Java 7 (Script Inside)

Posted: Sat Oct 27, 2012 9:01 pm
by bigj231
Althorax wrote:Script looks great, but I'm not sure what to enter at these points:

...

I don't like the third party option and I would like to try yours. I downloaded the following file:

~/Downloads/jre-7u7-linux-x64.tar.gz

Do you think you could give me some guidance?

Thanks in advance!!!
Sure thing. It's Java version 7 update 7. so just put in 7 and 7. It works like: jre-#VERSION NUMBER#u#UPDATE NUMBER#-linux-x64.tar.gz

Also, don't edit the script file. Just input the numbers and other data as needed.

Re: How to Install Java 7 (Script Inside)

Posted: Tue Nov 13, 2012 3:25 pm
by bigj231
I used this to install Java7 update 9, and it installed without issue. I used all the defaults, and everything worked as expected. Deleted the old and installed the new.

Re: How to Install Java 7 (Script Inside)

Posted: Thu Jan 10, 2013 7:33 pm
by mozkill
Excellent post. Thanks very much. This script will be useful. It would be nice if it also installed "galternatives", BTW.

Re: How to Install Java 7 (Script Inside)

Posted: Thu Jan 10, 2013 10:28 pm
by sagirfahmid3
Don't need galternatives. Go read the "update-alternatives" manual page, it's easy enough.

# update-alternatives --install /usr/bin/<program group, ex: /usr/bin/java)> <program group, ex: java> <location of executable, ex: /opt/java/...> <priority>

Re: How to Install Java 7 (Script Inside)

Posted: Fri Jan 11, 2013 6:01 pm
by mozkill
Of course, I know that, but since most users have a window system, for those users, it's nice to know that there is an "app for that".
sagirfahmid3 wrote:Don't need galternatives. Go read the "update-alternatives" manual page, it's easy enough.

# update-alternatives --install /usr/bin/<program group, ex: /usr/bin/java)> <program group, ex: java> <location of executable, ex: /opt/java/...> <priority>

Re: How to Install Java 7 (Script Inside)

Posted: Sat Jan 12, 2013 4:48 pm
by bigj231
I did not create the backend install code. I just created the front-end script to make it easier instead of having to plug in the different commands every time. The link to the original site is in the OP.
Also, most people already have update-alternatives, and I don't like having scripts putting unnecessary stuff on my system. If you would like to have galternatives installed, the script is free and open, so feel free to modify it to however you want. If you find a better way of installing java, I can put it in a script and either update or replace this script. Or if you want to do it yourself and need some help, just PM me and I'll help as much as I can.

Also, there is now a Java 7u10, so don't forget to update. I'm still trying to figure out if I can just wget the install file and make this a truly all-in-one script. If anyone knows where to find the files, let me know and I'll update the script to download them too.

Re: How to Install Java 7 (Script Inside)

Posted: Sun Jan 13, 2013 6:16 am
by grizzler
bigj231 wrote:Also, there is now a Java 7u10, so don't forget to update. I'm still trying to figure out if I can just wget the install file and make this a truly all-in-one script. If anyone knows where to find the files, let me know and I'll update the script to download them too.
That's already been done: http://www.duinsoft.nl/packages.php

Also, keep in mind the current Java versions are vulnerable and everyone is advised to keep Java switched off.
http://www.us-cert.gov/cas/techalerts/TA13-010A.html
http://blog.mozilla.org/security/2013/0 ... erability/

Next tuesday is Oracle's quarterly patch day. Hopefully they'll come up with something useful this time (they didn't the last time).

Edit: And they just keep on screwing up...
http://krebsonsecurity.com/2013/01/new- ... per-buyer/

Re: How to Install Java 7 (Script Inside)

Posted: Thu Jan 17, 2013 12:09 pm
by bigj231
I fixed the script so now it correctly installs java versions newer than update 9. Also pending in Opera plugin install support. Stay tuned for details.

Re: How to Install Java 7 (Script Inside)

Posted: Mon Jan 21, 2013 3:33 pm
by bigj231
Opera plugin support is now added as well as a few small bug fixes. I'll start a change log in the OP.

Re: How to Install Java 7 (Script Inside)

Posted: Fri Feb 01, 2013 4:31 pm
by bigj231
Java 7 update 13 has been released. Go get it and grab the new script.

Re: How to Install Java 7 (Script Inside)

Posted: Tue Jun 11, 2013 3:25 am
by jmdeking
thanks!