How to Install Java 7 (Script Inside)
Posted: 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.
And now for the promised chaneglog:
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
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.