How to learn Shell Scripting by installing Java JDK in DEBIAN

In this fifth (5th) inning en desdelinux.net about how "Learn Shell Scripting" next we will present the design of a Bash Shell script that I automated the tedious task of installing the Java JDK when OpenJDK it does not meet our requirements for high priority work or research endeavors.

Shell scripting

Certainly, OpenJDK and the plugin for browsers, the Iced TeaThey are easy to install and most of the time it covers all our expectations of development and online execution of Java applications.

They can be installed in the following way:

aptitude install default-jdk

aptitude install openjdk-7-jdk
aptitude install openjdk-7-jre

aptitude install openjdk-8-jdk
aptitude install openjdk-8-jre

aptitude install icedtea-netx
aptitude install icedtea-plugin

But sometimes the Java JDK (original / proprietary) It offers us greater compatibility, support and new functions than the proprietary one. Therefore, when we exhaust all our options of working with the OpenJDK and our distribution or repository does not have the latest version of Java JDK, perform manually or by means of a Bash Shell script said installation is something very practical.

Recall that Java Development Kit (Oracle JDK) is Official Development Kit of the Java programming language, an object-oriented development environment. And why install Java JDK?

Java JDK allows us to write applications and java applets inside or outside of an internet browser. JDK also includes Java Runtime Environment (JRE), Java compiler and Java API. Which is very useful for new and experienced programmers.

Java JDK not that necessary most of the time for a normal or basic User, sometimes just for simple things like a Embedded Console Online Game or for Medium or Advanced Users for things like Electronic certifications, because its buttons are java applets. Therefore, it is often essential to have it installed if you do not want to miss a good part of the web. That is, although there are many web pages that contain small portions of Java JDK (buttons, menus) or that are even designed entirely in Java JDK .

Therefore, Java JDK can not be missing in your Web Browser and Operating System usually!

Comment: It is not intended to recommend the installation of "Java JDK" but show way Shell scripting the process that is carried out secretly, that is, as deconstruct (Reverse Reengineering) the automated process that takes place when we install it via repository. Performing reverse reengineering of a package is useful to understand in depth how an application, package, software and even a Operating system, private or free, such as GNU / Linux. The same, for example, can be done with a Free Kernel for GNU / Linux or Adobe Flash Player for GNU / Linux.

Next the content to insert in the Bash Shell script or that must be executed manually for this purpose:


#!/bin/bash

################################################################################
# INICIO DEL MODULO DE INSTALACIÓN DE ORACLE JAVA JDK                                      
################################################################################

USER_NAME=`cat /etc/passwd | grep 1000 | cut -d: -f1`

HOME_USER_NAME=/home/$USER_NAME

cd $HOME_USER_NAME

cd /opt

cp $HOME_USER_NAME/jdk-* .

clear

echo "  Introduzca el numero de Versión de Java JDK (Ejemplo, 7 o 8): "

read NUM_VER
NV=${NUM_VER}

echo ""
echo ""

echo "  Introduzca el numero de SubVersion de Java JDK (Ejemplo, 80 o 45): "

read NUM_SUBVER
NSV=${NUM_SUBVER}

VERSION=jdk1.$NV.0_$NSV

echo ""
echo ""

echo "  NOTA: Este parámetro solo es usado para descargar el paquete .tar.gz "
echo "  Si no lo conoce y ya tiene los paquetes descargados escriba cualquier "
echo "  valor como por ejemplo (Ejemplo, b14 o b15) "

echo "  Introduzca el numero de revisión de Java JDK (Ejemplo, b14 o b15): "

read NUM_REV
NREV=${NUM_REV}

echo ""
echo ""

echo "  Introduzca el Tipo de Arquitectura del Paquete de Java JDK (Ejemplo, 1 para 32 Bit y 2 para 64 Bit): "

read T_ARQ
ARQ_PC=${T_ARQ}

if [ "$ARQ_PC" = "1" ]; then
   ARQ1=i586
   ARCHIVOJDK=jdk-"$NV"u$NSV-linux-$ARQ1.tar.gz
   ARQUITECTURA=i386
  else
   ARQ2=x64
   ARCHIVOJDK=jdk-"$NV"u$NSV-linux-$ARQ2.tar.gz
   ARQUITECTURA=amd64
fi

sleep 5

echo ""
echo ""
echo " CONFIRME QUE ESTE ES EL PAQUETE ORACLE JAVA JDK QUE COLOCO PARA SU INSTALACION"
echo ""
echo ""
echo " $ARCHIVOJDK - $VERSION - $NREV - $ARQUITECTURA"
echo ""
echo ""
echo " EN CASO DE NO SER CIERTO, CANCELE EL PROCESO CON CTRL+C, DE LO CONTRARIO"
echo " ESPERE 15 SEGUNDOS MIENTRAS EL PROGRAMA CONTINUA EL PROCESO DE INSTALACION."
echo ""
echo ""

sleep 15

# export http_proxy=http://192.168.3.250:8080
# export no_proxy="127.0.0.1, localhost, 192.168.0.0/22, tu_institucion.gob.ve:8080"

# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/"$NV"u$NSV-$NREV/$ARCHIVOJDK"
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/"$NV"u$NSV-$NREV/$ARCHIVOJDK"
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/"$NV"u$NSV-$NREV/$ARCHIVOJDK"
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/"$NV"u$NSV-$NREV/$ARCHIVOJDK"

# Descargar manualmente y colocar en la ruta /home/mi_usuario/
# http://www.oracle.com/technetwork/java/javase/downloads/index.html

tar -zxvf $ARCHIVOJDK -C /usr/lib/jvm/

# ACTUALIZACION VARIABLES DE ENTORNO PARA SUN JAVA JDK

echo "JAVA_HOME=/usr/lib/jvm/$VERSION" >> /etc/profile
echo "PATH=$PATH:$HOME/bin:$JAVA_HOME/bin" >> /etc/profile
echo "export JAVA_HOME" >> /etc/profile
echo "export PATH" >> /etc/profile


# INSTALACION Y CONFIGURACION DE LA VERSION ACTUAL DE ORACLE JAVA JDK

update-alternatives --install /usr/bin/java java /usr/lib/jvm/$VERSION/bin/java 1
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/$VERSION/bin/javac 1
update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/$VERSION/bin/javaws 1
update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/$VERSION/bin/jar 1

update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /usr/lib/jvm/$VERSION/jre/lib/$ARQUITECTURA/libnpjp2.so 1

update-alternatives --set java /usr/lib/jvm/$VERSION/bin/java
update-alternatives --set javac /usr/lib/jvm/$VERSION/bin/javac
update-alternatives --set javaws /usr/lib/jvm/$VERSION/bin/javaws
update-alternatives --set jar /usr/lib/jvm/$VERSION/bin/jar

update-alternatives --set mozilla-javaplugin.so /usr/lib/jvm/$VERSION/jre/lib/$ARQUITECTURA/libnpjp2.so


# CONFIGURACION DE VERSION ACTUAL DE ORACLE JAVA JDK EN MOZILLA FIREFOX Y OPERA BROWSER

cd /usr/lib/mozilla/plugins/

rm -f libnpjp2.so

ln -s /usr/lib/jvm/$VERSION/jre/lib/$ARQUITECTURA/libnpjp2.so


# VERIFICACION Y GUARDADO DE LA ACTUALIZACION DE LA VERSION ACTUAL DE ORACLE JAVA DESCARGADA

java -version

javac -version

. /etc/profile

# FINALIZACION DE INSTALACION DE ORACLE JAVA DESCARGADA

rm -f jdk-*

cd $HOME_USER_NAME

rm -f jdk-*

su - $USER_NAME -c "xdg-open 'http://www.java.com/es/download/installed.jsp'" &

################################################################################
# FINAL DEL MODULO DE INSTALACIÓN DE ORACLE JAVA JDK                                   
################################################################################

==================================================

Note: I personally use it by manually downloading the file Java JDK updated manually, so I use wget download lines commented, and I place my script-java-jdk.sh in the path / home / my_user together with the file Java JDK downloaded and run it with the command command $ bashscript-java-jdk.sh . And in less than 30 seconds I have everything functional. After this you can install any application in the Operating system that requires Java JDK and run any java webapps in a Mozilla Firefox-based browser.

Remember, the idea is to understand how each line by line, command by command, variable by variable works, to understand and learn Shell Scripting. So with this new post I leave you with an exciting new research assignment.

PROCEDURE TUTORIAL

Personal folder_016

root @ hostmovil-sysadmin: -home-sysadmin_001

root @ hostmovil-sysadmin: -home-sysadmin_004

root @ hostmovil-sysadmin: -home-sysadmin_005

root @ hostmovil-sysadmin: -home-sysadmin_006

root @ hostmovil-sysadmin: -home-sysadmin_008

root @ hostmovil-sysadmin: -home-sysadmin_009

root @ hostmovil-sysadmin: -home-sysadmin_010

Check Java Version - Iceweasel_011

Safety Information_012

Check Java Version - Iceweasel_013


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   zetaka01 said

    Shell scripting and java. The opposite. A pseudocompiled language like java and an interpreted language like shellscript. With java you need a JVM.
    When you reinvent the wheel, well, well.
    Compile it to C, but to Java, a lag.
    Congratulations

    1.    Anton said

      zetaka01, I think you have not understood the purpose of the article. Sometimes it's good to think twice.

  2.   Jose Albert said

    Greetings.

    Textually I wrote: «Observation: The purpose is not to recommend the installation of" Java JDK "but to show via Shell Scripting the process that is carried out secretly, that is, how to deconstruct (Reverse Reengineering) the automated process that is carried out when we install it via the repository . Carrying out reverse reengineering of a package is useful to understand in depth how an application, package, software and even an Operating System, proprietary or free, like GNU / Linux works. The same, for example, can be done with a Free Kernel for GNU / Linux or Adobe Flash Player for GNU / Linux ».

    It was supposed to be impossible to think (interpret) what you thought (interpret), but it doesn't matter!

    Let me clarify: These tutorials are for those who do not know Shell Scripting, learn Shell Scripting by reconstructing the installation and configuration processes of some software or procedure, proprietary or free on a GNU / Linux Operating System.

    Equally for you: Congratulations and many blessings!

  3.   arnoldbr said

    Regards. Thanks for your articles. Very informative. Keep posting like this.

  4.   zetaka01 said

    Well, I am the most opposite of virtual machines. JIT compilers keep getting better but the underlying machine slows it down. I prefer a lighter approach like the GO language, for other native compilers.
    I really miss a python compiler to native.
    A greeting.

  5.   zetaka01 said

    And yes, you are right, as soon as I read about the JVM I disconnected from the article. A virtual machine, JVM or Mono, etc, is like an operating system on top of your operating system.
    My apologies and greetings.

  6.   zetaka01 said

    Ah, done without h.

  7.   Jose Albert said

    Relax, imagine that you had not read the entire article!

  8.   Jose Albert said

    An advanced example of what can be done with Shell Scripting.

    LPI-SB8 Test ScreenCast (LINUX POST INSTALL - SCRIPT BICENTENARIO 8.0.0)
    (lpi_sb8_adaptation-audiovisual_2016.sh / 43Kb)

    See Screencast: https://www.youtube.com/watch?v=cWpVQcbgCyY

  9.   Ruben said

    Thank you very good greetings from Venezuela.