How to Install Java 7 (Script Inside)

Forum rules
Before you post please read this

How to Install Java 7 (Script Inside)

Postby bigj231 on Mon Oct 08, 2012 11:15 am

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.
Last edited by bigj231 on Sat Mar 30, 2013 1:21 pm, edited 7 times in total.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Linux Mint is funded by ads and donations.
 

Re: How to Install Java 7 (Script Inside)

Postby sagirfahmid3 on Mon Oct 08, 2012 1:19 pm

Nice, I made a similar one a while ago, but I've been too busy with homework. Good to see you took this up =)
User avatar
sagirfahmid3
Level 6
Level 6
 
Posts: 1054
Joined: Sun Sep 04, 2011 12:39 pm

Re: How to Install Java 7 (Script Inside)

Postby bigj231 on Sat Oct 13, 2012 10:16 am

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.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: How to Install Java 7 (Script Inside)

Postby Althorax on Wed Oct 24, 2012 6:17 pm

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!!!
Althorax
Level 1
Level 1
 
Posts: 3
Joined: Thu Jul 12, 2012 12:51 pm

Re: How to Install Java 7 (Script Inside)

Postby bigj231 on Sat Oct 27, 2012 9:01 pm

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.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: How to Install Java 7 (Script Inside)

Postby bigj231 on Tue Nov 13, 2012 3:25 pm

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.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: How to Install Java 7 (Script Inside)

Postby mozkill on Thu Jan 10, 2013 7:33 pm

Excellent post. Thanks very much. This script will be useful. It would be nice if it also installed "galternatives", BTW.
mozkill
Level 1
Level 1
 
Posts: 5
Joined: Thu Jan 10, 2013 7:22 pm

Re: How to Install Java 7 (Script Inside)

Postby sagirfahmid3 on Thu Jan 10, 2013 10:28 pm

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>
User avatar
sagirfahmid3
Level 6
Level 6
 
Posts: 1054
Joined: Sun Sep 04, 2011 12:39 pm

Re: How to Install Java 7 (Script Inside)

Postby mozkill on Fri Jan 11, 2013 6:01 pm

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>
mozkill
Level 1
Level 1
 
Posts: 5
Joined: Thu Jan 10, 2013 7:22 pm

Re: How to Install Java 7 (Script Inside)

Postby bigj231 on Sat Jan 12, 2013 4:48 pm

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.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: How to Install Java 7 (Script Inside)

Postby grizzler on Sun Jan 13, 2013 6:16 am

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/
Last edited by grizzler on Fri Jan 18, 2013 5:07 am, edited 1 time in total.
grizzler
Level 4
Level 4
 
Posts: 437
Joined: Wed Jun 15, 2011 5:19 pm
Location: The Hague, NL

Re: How to Install Java 7 (Script Inside)

Postby bigj231 on Thu Jan 17, 2013 12:09 pm

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.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: How to Install Java 7 (Script Inside)

Postby bigj231 on Mon Jan 21, 2013 3:33 pm

Opera plugin support is now added as well as a few small bug fixes. I'll start a change log in the OP.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: How to Install Java 7 (Script Inside)

Postby bigj231 on Fri Feb 01, 2013 4:31 pm

Java 7 update 13 has been released. Go get it and grab the new script.
Running on a 4-slot toaster @ 60Hz
User avatar
bigj231
Level 5
Level 5
 
Posts: 793
Joined: Fri Feb 26, 2010 10:16 am
Location: Middle of Nowhere

Re: How to Install Java 7 (Script Inside)

Postby jmdeking on Tue Jun 11, 2013 3:25 am

thanks!
jmdeking
Level 2
Level 2
 
Posts: 58
Joined: Sun Jul 15, 2012 7:59 am

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest