Build your program step by step using Shell Scripting - Part 4

In previous entries in this series of publications, we recalled how to implement a:

Shell scripting

And in previous ones, how to implement a Shebang and a BSM (Bash Strict Mode / Strict Bash Mode).

Best practices to create a Shell Script in GNU / Linux - Part 1

Best practices to create a Shell Script in GNU / Linux - Part 2

Here is an example of a Optimization module, taking as an example one of my programs (applications) facts in a Shell script called Linux Post Install - Bicentennial Script 8.0:

This should be the module (section) to install the base packages necessary for the proper functioning of the same, or execute the minimum actions necessary to update, maintain or perform the Work Environment or Operating System so that everything runs satisfactorily. I personally add the following lines to create this module:


###############################################################################
# INICIO DEL MODULO DE OPTIMIZACIÓN AL LINUX POST INSTALL - SCRIPT BICENTENARIO               
###############################################################################

# Sección que instala los paquetes bases del LPI-SB

echo -e '\a'

apt update && apt install dialog gxmessage zenity espeak gksu -y && apt install -f && dpkg --configure -a

if [ $? = 0 ]; then

     echo ""
     echo ""
     echo "#--------------------------------------------------------#"
     echo "#LA INSTALACIÓN DE LOS PAQUETES HA CULMINADO EXITOSAMENTE#"
     echo "#--------------------------------------------------------#"
     echo ""
     echo ""

     play /usr/share/sounds/info.wav 2> /dev/null

     sleep 3
     clear

else

     echo ''
     echo ''
     echo '#--------------------------------------------------------#'
     echo '# LA INSTALACIÓN DE LOS PAQUETES NO CULMINO EXITOSAMENTE #'
     echo '#--------------------------------------------------------#'
     echo ''
     echo ''

     play /usr/share/sounds/warning.wav 2> /dev/null

     sleep 3
     clear

     echo ''
     echo ''
     echo '#--------------------------------------------------------#'
     echo '#                  EJECUTE MANUALMENTE                   #'
     echo '# UN MANTENIMIENTO PREVENTIVO Y CORRECTIVO EN SU SISTEMA #'
     echo '#   EJECUTANDO LA SIGUIENTES ORDEN DE COMANDO, 1 HA 1:   #'
     echo '#                                                        #'
     echo '#                       apt update                       #'
     echo '#                     apt install -f                     #'
     echo '#                   dpkg --configure -a                  #'
     echo '#                       apt upgrade                      #'
     echo '#                                                        #'
     echo '#   LUEGO INSTALE MANUALMENTE LOS PAQUETES NECESARIOS    #'
     echo '#         CON LA ORDEN DE COMANDO SIGUIENTE:             #'
     echo '#                                                        #'
     echo '#      apt install dialog gxmessage zenity espeak -y     #'
     echo '#                                                        #'
     echo '#  AHORA, VUELVA HA INTENTAR EJECUTAR EL SCRIPT LPI-SB   #'
     echo '#--------------------------------------------------------#'
     echo ''
     echo ''

     sleep 3
     clear

     play /usr/share/sounds/info.wav 2> /dev/null

     exit 0

fi

wget -o /dev/null --user-agent="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36" -O "/tmp/audio.mp3" "https://translate.google.co.ve/translate_tts?ie=UTF-8&q=BIENVENIDO%20AL%20LINUX%20POST%20INSTALL%20-%20SCRIPT%20BICENTENARIO&tl=es&total=1&idx=0&textlen=54&tk=511133.124198&client=t&prev=input&ttsspeed=0.24" ; play -q /tmp/audio.mp3

wget -o /dev/null --user-agent="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36" -O "/tmp/audio.mp3" "https://translate.google.co.ve/translate_tts?ie=UTF-8&q=ESTIMADO%20USUARIO%2C%20ESPERE%20UNOS%20SEGUNDOS%20MIENTRAS%20EL%20PROGRAMA%20SE%20CARGA%20E%20INICIA&tl=es&total=1&idx=0&textlen=77&tk=337132.200023&client=t&prev=input" ; play -q /tmp/audio.mp3

###############################################################################
# FINAL DEL MODULO DE OPTIMIZACIÓN AL LINUX POST INSTALL - SCRIPT BICENTENARIO               
###############################################################################

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

As you can see, this module runs a aptitude update, followed by the installation of the packages dialog gxmessage zenity speak gksu, continuing with the command orders aptitude install -f y dpkg --configure -a. And in case if and only if everything has been executed satisfactorily, a visual message by terminal of successful completion with a sonic alert and I continued with the next step (module / section) of the Shell script. Otherwise, a visual message by terminal of unsuccessful realization with a sonic alert, with another visual message by terminal recommending manual actions to execute to avoid the error achieved again and then finish the execution of the Shell script.

With respect to the last 2 lines of the module, those that start with wget command, for now these are not essential, as these are part of a experimental procedure adapted by me to achieve the voice support of a Shell script with internet connection using the Online voice synthesizer from Google Translate and her sensual female voice, and thus replace the synthesizer with robotic voice (male / female) provided locally by the GNU / Linux Operating Systems with the packages (programs) espeak, festival, festvox, mbrola, speech and stardict.

Recommendation:

READ THE DOCUMENT: «THE CATHEDRAL AND THE BAZAR»

The Cathedral and the Bazaar is a kind of manifesto created by Eric S Raymond in 1.998 to try to explain from your point of view and personal experience (Creation of the program fetchmail) what he perceived about the successful creation and evolution of Linux and its related programs, especially from the perspective of the difference between the Software Development Models, which he personally called: Cathedral Model and Bazaar Model.

My summary analysis of that document is as follows:

This reading suggests or presents the vision that within the world of Software engineering there are “two completely different styles of development, cathedral model, applicable to most of the developments carried out in the world of Commercial software, in front of bazaar model, more typical of the world Linux ". Emphasizing that these 2 models are derived from opposite starting points on the nature of the software debugging process, and from his particular theory about what he called Linus's law which stated the following: "Given a sufficient number of eyes, all errors are irrelevant" or in other words: "With a sufficient number of eyes, all mistakes are trifles."

Also in this reading the author emphasizes the word Chippers, which in my opinion the author expressed as a kind of High-level user capable of efficiently understanding and exploiting a program, and of detecting, suggesting or implementing corrections or modifications of efficient form and substance for the entire user community. I liked this self-suggested concept a lot since I think it is correct, however, I will leave one that I also like a lot because it is much more global and / or generic.

Chippers

"Linux is subversive." Why? The first thing this reading tells us is that:

Until then there was a huge diversity of standardized Software Development methods or models that were based on a "More centralized and planned approach from the start" as a result of the act of designing Software being taken as something related to a X Factor that leads to “Some critical complexity”. And that despite the fact that this already existed in the Unix worldIn other words, work consisting of small tools, rapid prototype development and evolutionary programming, the appearance of the Free Software development philosophy under Linux took the matter to another level of sophistication.

As a result of this, While Private Software Development was made of "Silent and reverent way", as you build a Cathedral, Free Software Development (Linux) was made of "bustling way and with multiple agendas (paths) and approaches (proposals) ", just as you were in a great Bazaar.

Finally, it exposes a series of premises worth breaking down and digesting in their proper context to understand those who develop for the Community of Free Software users. These premises are:

  1. ALL GOOD JOBS IN SOFTWARE BEGINS TRYING TO PLEASE A PERSONAL PROBLEM FROM WHICH YOU SCHEDULE THEM.
  2. GOOD PROGRAMMERS KNOW WHAT TO WRITE. THE GREATEST KNOW WHAT TO REWRITE (AND REUSE).
  3. THINK ABOUT DISPOSING AT LEAST ONE: YOU WILL END UP DOING IT ANYWAY. "
  4. IF YOU HAVE THE RIGHT ATTITUDE, INTERESTING PROBLEMS WILL FIND YOU.
  5. WHEN A PROGRAM IS NO LONGER INTERESTING YOU, YOUR LAST DUTY IS TO PASS IT ON TO A COMPETENT SUCCESSOR.
  6. TREATING YOUR USERS AS COLLABORATORS IS THE LESS COMPLICATED WAY TO RAPIDLY IMPROVE AND EFFECTIVELY DEBUG A PROGRAM.
  7. RELEASE SOON. LAUNCH IT OFTEN. AND LISTEN TO YOUR USERS.
  8. GIVEN A WIDE ENOUGH BASE OF TESTERS AND CONTRIBUTORS, ALMOST ALL PROBLEMS WILL BE IDENTIFIED QUICKLY AND THEIR SOLUTION WILL BE OBVIOUS TO SOMEONE.

Plus 11 other remaining premises that are more of the sobering type (moral), which does not come with the story but with what is interpreted by each reader (developer), which in my very particular case, led me to the following conclusions:

Conclusions

I hope you liked this information and it is useful, since The Reading of the Cathedral and the Bazaar is a mandatory reference for all those who program any Free Software Development, no matter how large or small.

Later, in future posts we will continue to see an example of modules (sections) that perform functions such as:

  • USER AUTHORIZATION MODULE WITH PASSWORD
  • MODULE OF DETECTION OF THE ARCHITECTURE OF THE OPERATING SYSTEM
  • CODING LANGUAGE CONFIGURATION MODULE
  • PROXY CONFIGURATION MODULE FOR THE EXECUTION ENVIRONMENT

Among many others!

And as always, I recommend go learning in a self-taught way about the commands: gksu, dialog, gxmessage, zenity, espeak, play, among many others to create graphical interfaces by Terminal or for the User's Desktop, with sonic or multimedia alerts, and advance knowledge that they will use later.

Remember that these and any other recommendations on some module, function, variable, command or action in general it can be carried out many ways, and what is shown here is only one simple way, Of the many possible and probable ways in which said action can or could be carried out!

Just to finish I leave you, a Screencast made by me, to show you what you would be capable of, after finishing this Shell Scripting online course in DesdeLinux:

LPI-SB8 Test ScreenCast

(LINUX POST INSTALL - BICENTENNIAL SCRIPT 8.0.0) - Part 2


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.