M01: Introduction to Operating Systems TU3: Installing specific purpose software
ASIX1
Pràctical Exercise 1: How to create a .deb and .rpm package
17-04-2020

PRACTICAL EXERCISE 1: HOW TO CREATE A .deb AND .rpm  PACKAGE

GENERAL CONDITIONS

1- Deadline: 26-04-2020.
2- Send your files attached to an e-mail with the following specifications:
     a) E-mail address:
cf(at)collados.org or jordi.binefa(at)fje.edu depending who is your teacher
     b) File Name:

        b.1)
ASIX1: asix1_surname_name_m01tu03pr1.tar.gz
        b2.) DAW1: daw1_surname_name_m01tu03pr1.tar.gz     
     c)
Subject:
         c.1)
ASIX1: asix1_surname_name_m01tu03pr1
         c.2)
DAW1: daw1_surname_name_m01tu03pr1
3- Make this report individually.
4- Left, right, top and bottom margins: 2cm.
5- Character format: a) Font:Times New Roman (or Liberation Serif), b) Size: 10, c) Questions typeface: Bold, d) Answers typeface: Regular.
6- Page numbering on footer bar.


MEETING
1.-  Date: Friday, the 17th of April, 2020
2.- Time: From 3:30 p.m. to 5 p.m.
3.-  Place: Jesuïtes Educació NET --> Videoconferències --> Join a meeting --> meeting name: https://meet.google.com/eus-nctg-eue
4- Before attending the meeting you should read the DOCUMENTATION section  and play the videotutorials



DOCUMENTATION

0- Videotutorials

*ASIX1: https://drive.google.com/open?id=17z0w6PsMmlb7r0CDSnBImVm1bahtGlvH

* DAW1: https://drive.google.com/open?id=1jpzbJoggSYqQLAl8o_gfAK5Y4njW6a8h


* Documentation section 2
and help for question 1 correspond to videoclips  to: 01-Creating tarball files.ogv  and   02-Building and Intalling with Makefile.ogv
*
Documentation section 3 and help for question 2 correspond to videoclips: 03-Installing checkinstall   and   04-Creating deb packages - C software.ogv
* Documentation section 4 and help for question 3 correspond to videoclip: 05-Creating deb packages - Bash software.ogv
* Documentation section 5 and help for question 4 correspond to videoclip: 07-deb_rpm.ogv
*
Help for questions 5 to 6 correspond to videoclips:
04-Creating deb packages - C software.ogv
* Help for question 7 correspond to videoclip:  07-deb_rpm.ogv
* Help for question 8 correspond to videoclip:  05-Creating deb packages - Bash software.ogv
* Help for question 9: 06-Creating deb packages - Python software.ogv


1- How to install software on Debian/Ubuntu


Installing software on Linux involves most of the time running a package manager to download a sofware package from a software repositories.  Additional methods of installing software on your system can involve download, compile and install sofware  from its source code or download a software package to your hard disk and install the software with the help of a package installer

A software package is a special kind of file used to distribute and install software (text editors, web browsers, libraries, servers,compiler, interpreters, drivers....) on your operating system. A software package consists of  a set of files gathered into one single file. Some of those files are the software itself that will be installed on the system. Other files contains metada, in other words, information about the software (software's name, version number, dependencies and so on). Also, a package can contain extra related material such as manuals, guides, examples and tutorials. On Linux,  a usual method (not the only) to install software on the operating system is by downloading and installing a software package that provide us with the desired software. On Debian and Ubuntu, deb is the format, as well as extension, of software packages. For instance, geany_1.24.1+dfsg-1_amd64.deb is the software package
used to distribute and install geany on the 64 bits version of Debian 8.6. On RedHat, Fedora, CentOS or SuSE, rpm is the format, as well as extension, of software packages. For instance, geany_1.30.1-1.fc27x86_64.rpm is the software package used to distribute and install geany on the 64 bits version of Fedora.

A package management system or package manager
is a collection of software tools that provides to system administrators  an easy method of installing, upgrading, configuring, and removing software packages. Also, with the help of a package manager, a system administrator can effortlessly automate the process of installing, upgrading, configuring, and removing software packages in a consistent manner. The dpkg family of tools is used to install .deb packages  on Debian and its derivatives, such as Ubuntu and Mint. Programs such as dpkg, apt-get, aptitude or Synaptic are part of the dpkg family of tools.

A software repository
is a storage location from which software packages (both source and binary) may be retrieved and installed on a computer. Normally, a software repository is stored in a server  accessible via an internet connection. The dpkg family of tools usually downloads and intalls  .deb files from software repositories stored in a server accessible via an HTTP or FTP connection.

Another method of installing .deb packages on Debian is via a package installer  such as Gdeb that provides us with a simple way to install a local (i.e, stored in your computer) .deb package. Gdebi is a command line tool but  a graphical user interface is provided by the software developer as well.

Sometimes you will install software unpacking a binary archive because some Linux software is distributed in precompiled form designed to run on any Linux distribution without installation. For example, the “Dynamic” download Skype offers is a .tar.bz2 file. This is just an archive, like a ZIP file — you’d extract it to a folder on your computer and double-click the executable inside it to run it. In other words, it is like installing software on Windows systems. That is not by far a typycal way of installing software on Debian and its derivatives.

Also, you can install software via a tarball files. A Tarball archive  is a  .tar.gz or .tar.bz2 file usually stored in a server accessible via an internet. Tarballs are used for programs which are not compiled, i.e. they are presented as source code. In order to install this kind of software you should follow this procedure: a)  Extract data from the tarball archive, b) Compile the source code, c) Install the software on your system. That could be a difficult  way to install software and, in order to make it easier, developers provide us with an extra script called configure that checks if everything you need to complie your software is installed on your system (compilers, libraries,..)  and builds a new file called Makefile. Sometimes, Makefile is directly provided by the software developer. A software developement tool called make, with the help of information stored in Makefile,  will build and install the new software on your system. Most of the time. a Makefile archive provides make with information about how to uninstall and remove software previously installed.  



2- How to buid a simple tarball software packege

Step 1) Source code development


We are going to develop a software that shows us our login name at system. Make a new directory called loginteller on your system. Change to the newly created directory. Start an instance of Geany and write the folliwing source code in C language:

/* loginteller.c
 * Based on monousuar.c at http://www.binefa.net/gnu/gcc/processos/Informacio_d_usuari.html
 * www.binefa.cat
 * 20120507
*/
#include <stdio.h>
#include <unistd.h>    // getlogin()
#include <stdlib.h>    // exit()

int main(){
    char *szLogin;
   
    if((szLogin = getlogin())==NULL){
        perror("getlogin");
        exit(EXIT_FAILURE);
    }  
    printf("Your login name at the system is : %s\n",szLogin);

    return (0);
}


In order to check if your code works properly, run the following commnads:

dacomo@inf1-dacomo:~/loginteller$ gcc  loginteller.c  -o  loginteller
dacomo@inf1-dacomo:~/loginteller$ ./loginteller

Your terminal will show you the following message:

Your login name at the system is: dacomo

Of course, the message displayed by the terminal depends on what your username is in the system.

Step 2) Creating a Makefile archive

A Makefile typically starts with some variable definitions which are then followed by a set of target entries for building specific targets (typically .o & executable files in C) or executing a set of command associated with a target label. We are going to develop a Makefile for easily:
a) Compiling the source code
b) Cleaning binary files
c) Installing binary files on your system
d) Uninstalling binary files on your system

Start an instance of Geany and write the following Makefile:


############################################################################
# Makefile for building: loginteller
# 20120508 - www.binefa.cat
#############################################################################
####### Compiler, tools and options

CC              = gcc
CFLAGS          = -o
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE        = rm -f
####### Files
SOURCES   = loginteller.c
DESTDIR   = /usr/local/bin/
TARGET    = loginteller
####### Compilation and cleaning.
Be careful, you have to write a TAB character at the beginnig of each command. Do not write whitespace characters.
loginteller:
    $(CC) $(SOURCES) $(CFLAGS) $(TARGET)
clean:
    $(DEL_FILE) $(TARGET)
####### Install and uninstall. Be careful, you have to write a TAB character at the beginnig of each command. Do not write whitespace characters.
install: $(TARGET)
    $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)
uninstall:
    $(DEL_FILE) $(DESTDIR)/$(TARGET)

Now, you can easily:
a) Compile loginteller.c running the following command: make (or make loginteller)
b) Remove an old binary
running the following command: make clean
c) Install a binary
on your system running as a sudo user the following command: make install
d) Uninstall a binary on your system running as a sudo user the following the command: make uninstall


Step3) Creating a README file


A README file is a text file that contains information for the user about the program. README files often contain instructions and additional help. Add a README file with the following content:


*************************************************************************
*                                                                        *
*                   loginteller v1.01                                    *
*            Copyright (C) 2010-2020, jobima & dacomo                    *
*                                                                        *
**************************************************************************

Welcome to the loginteller program!  This program, once installed as
/usr/local/sbin/loginteller,  tells current login name at the system.


SOURCES
=========

Web:      http://www.inf1-jobima.cat/software/utils/loginteller/
FTP:      ftp://ftp.inf1-jobima.cat/pub/utils/loginteller/loginteller.tar.gz


INSTALLATION
============

Installation of  the loginteller  is quite easy.   Simply follow these steps as
a user with root privileges:

1. Building:

       # make

2. Installing:

       # sudo make install

3. You are finished.


LICENSE
=======

The  logiteller program  is  distributed  under the  terms  of the  GNU
General Public  License.  The  copyright on this  program belongs  to Jordi
Binefa.  The actual license appears in file /usr/share/common-license/GPL.

Even though  the GNU General Public  License does NOT require  you to send
your modifications back to the author,  it is considered "good form" to do
so,  as this  allows your  modifications  to be  incorporated into  future
versions of the program, allowing others to benefit from them.


FEEDBACK
========

Your comments, suggestions, corrections and enhancements are always warmly
welcomed!  Please send these to:

E-mail:   jobima@inf1-jobima.cat



Step 4) Creating a .tar
.gz file

Run the following command:

dacomo@inf1-dacomo:~/loginteller$ tar cfz loginteller-1.01.tar.gz loginteller.c Makefile README

3- How to build a .deb package

3.1.- Installing checkinstall

In order to build a .deb package you need an application called checkintall installed on your system. In ordre to install checkintall run the following commands:

dacomo@inf1-dacomo:~$ sudo aptitude update
dacomo@inf1-dacomo:~$ sudo aptitude install checkinstall

But If 
If your system tells you that it couldn't find a package called checkinstall then add the following line to /etc/apt/sources.list:

deb http://deb.debian.org/debian buster-backports main

and run again:

dacomo@inf1-dacomo:~$ sudo aptitude update
dacomo@inf1-dacomo:~$ sudo aptitude install checkinstall

3.2- Building a .deb package

If we want to create a .deb package for loginteller.c we should follow these steps:

a
) Create a Makefile for compiling, cleaning, installing and uninstalling loginteller on your system. Makefile and loginteller.c have to be stored in the same directory.

b)
If you had installed a previous version of loginteller from a tarball package then,  remove any  binary running make clean and uninstall the software running make uninstall.

c)
Run checkinstall:

dacomo@inf1-dacomo:~/loginteller$ sudo checkinstall

checkinstall 1.6.3, Copyright 2010 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.


The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs?  [y]:

Preparing package documentation...OK

*** No known documentation files were found. The new package
*** won't include a documentation directory.

Please write a description for the package.
End your description with an empty line or EOF.
>> It tells current login name at the system
>>

*****************************************
**** Debian package creation selected ***
*****************************************

This package will be built according to these values:

0 -  Maintainer: [ root@inf1-dacomo ]
1 -  Summary: [ It tells current login name at the system ]
2 -  Name:    [ loginteller ]
3 -  Version: [ 20200414 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ loginteller ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Recommends: [ ]
12 - Suggests: [ ]
13 - Provides: [ loginteller ]
14 - Conflicts: [  ]
15 - Replaces: [  ]

Enter a number to change any of them or press ENTER to continue: 0
Enter the maintainer's name and e-mail address:
>> dacomo@inf1-dacomo  (NOTE: dacomo must be change into your user name)

This package will be built according to these values:

0 -  Maintainer: [ dacomo@inf1-dacomo ]
1 -  Summary: [ It tells current login name at the system ]
2 -  Name:    [ loginteller ]
3 -  Version: [
20200414 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ loginteller ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Recommends: [ ]
12 - Suggests: [ ]
13 - Provides: [ loginteller ]
14 - Conflicts: [  ]
15 - Replaces: [  ]

Enter a number to change any of them or press ENTER to continue: 3
Enter new version:
>> 0.1

This package will be built according to these values:

0 -  Maintainer: [ dacomo@inf1-dacomo ]
1 -  Summary: [ It tells current login name at the system ]
2 -  Name:    [ loginteller ]
3 -  Version: [ 0.1 ]

4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ loginteller ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Recommends: [ ]
12 - Suggests: [ ]
13 - Provides: [ loginteller ]
14 - Conflicts: [  ]
15 - Replaces: [  ]

Enter a number to change any of them or press ENTER to continue: 6
Enter the new software group:
>> utilities

This package will be built according to these values:

0 -  Maintainer: [ dacomo@inf1-dacomo ]
1 -  Summary: [ It tells current login name at the system ]
2 -  Name:    [ loginteller ]
3 -  Version: [ 0.1 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ utilities ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ loginteller ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Recommends: [ ]
12 - Suggests: [ ]
13 - Provides: [ loginteller ]
14 - Conflicts: [  ]
15 - Replaces: [  ]

Enter a number to change any of them or press ENTER to continue:

Installing with make install...


========================= Installation results ===========================
gcc loginteller.c -o loginteller
install -m 755 -p loginteller /usr/local/bin

======================== Installation successful ==========================

Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building Debian package...OK

Installing Debian package...OK

Erasing temporary files...OK

Writing backup package...OK
OK

Deleting temp dir...OK



*********************************************************************

 Done. The new package has been installed and saved to

 /home/dacomo/loginteller/loginteller_0.1-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r loginteller

**********************************************************************

d) 
At this moment a new .deb package loginteller_0.1-1_amd.64.deb has been build in your working directory and automatically the package has been installed on your system. Run the following command:

dacomo@inf1-dacomo:~/loginteller$ ls

and your terminal will show you the following files:


backup-041420202048-pre-logiteller.tgz  description.pak  loginteller  loginteller_0.1-1_amd64.deb loginteller.c Makefile

 and the the command:

dacomo@inf1-dacomo:~/loginteller$ aptitude search loginteller

and your terminal will show you the following message:

i    loginteller                - It tells current login name at the system

e) Run the following command:

dacomo@inf1-dacomo:~/loginteller$ aptitude show loginteller

and your terminal will show you the following message:

Package: loginteller
Version: 0.1-1
New: yes
State: installed
Automatically installed: no
Priority: extra
Section: utilities
Maintainer: dacomo@inf1-dacomo
Architecture: amd64
Uncompressed Size: 36.9 k
Description: It tells current login name at the system


f
) If you want to remove loginteller from your system run the following command:
sudo  dpkg  -r  loginteller  (do not worry about any warning message) 

g) If you want to install loginteller through the terminal run the following command:  sudo  dpkg  --install  loginteller_0.1-1_amd64.deb


4- How to build a .deb package for a bash script

In this section we will learn how to build a .deb package for a bash script with dependencies. In order to follow this section you should download   loginteller2.tar.gz.  The contents of loginteller2.tar.gz are a  script called loginteller2.sh. It shows your current login name and the contents of your personal folder in a tree-like format. In order to run loginteller2.sh, a command called tree (which is able to list contents of directories in a tree-like format) must be installed in your system. In other words, tree is a dependency of loginteller2.sh.  This is the loginteller2.sh source code:

#!/bin/bash
# loginteller2.sh -  shows your current login name and the contents of your personal folder in a tree-like format
# 20160506 - Binefa & Collados
clear
echo "Your login name at the system is : $USER"
echo
echo "Press  the <Enter> key to show the contents of your personal folder"
read
echo
tree /home/$USER
exit 0


and a  Makefile archive to install and uninstall loginteller2.sh on your system. This is the Makefile content:

#############################################################################
# Makefile for building: loginteller2.sh
# 20200414 - Binefa & Collados
#############################################################################

####### Options and tools.
Be careful, you have to write a TAB character at the beginnig of each command. Do not write whitespace characters.
DESTDIR       = /usr/local/bin/
TARGET        = loginteller2.sh
INSTALL_PROGRAM = install -m 755 -p

####### Install and uninstall.
Be careful, you have to write a TAB character at the beginnig of each command. Do not write whitespace characters.
install:
    $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)

uninstall:
    rm -f $(DESTDIR)/$(TARGET)


Make a new directory called loginteller2 on your system. Change to the newly created directory. Download and unpackage loginteller2.tar.gz. Now, run checkinstall and create a new .deb package with the following configuration:

0 -  Maintainer: [ jobima@inf1-jobima ]
1 -  Summary: [
It tells current login name at the system ]
2 -  Name:    [ loginteller2 ]
3 -  Version: [ 0.1 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ utilities ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ loginteller2 ]
9 -  Alternate source location: [  ]
10 - Requires: [ tree ]
11 - Recommends: [ ]
12 - Suggests: [ ]
13 - Provides: [ loginteller2 ]
14 - Conflicts: [  ]
15 - Replaces: [  ]


Pay close attention to the entry 10 - Requires:. In order to work properly, loginteller2.sh needs tree installed on the system and therefore, you have to fill correctly this entry. If tree is no intalled on your system, the following message will be displayed:

Installing Debian package... FAILED!

*** Failed to install the package

Do you want to see the log file?  [y]:

But, if tree was previously installed on your system, everything will work fine and the following message will be displayed:

  ======================== Installation successful ==========================

Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

1-Compressing man pages...OK

Building file list...OK

Building Debian package...OK

Installing Debian package...OK

Erasing temporary files...OK

Writing backup package...OK
OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been installed and saved to

 /home/dacomo/loginteller2/loginteller2_0.1-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r loginteller2

**********************************************************************


Now a new .deb package loginteller2_0.1-1_amd.64.deb has been build in your working directory and automatically the package has been installed on your system. Run the following command:

dacomo@inf1-dacomo:~/loginteller$ ls

and your terminal will show you the following files:

 
description.pak  loginteller2_0.1-1_amd64.deb loginteller2.sh Makefile

  If you run the following command:

dacomo@inf1-dacomo:~/loginteller$ aptitude search loginteller2

your terminal will show you the following message:

i    loginteller2                - It tells current login name at the system

and if you run:

dacomo@inf1-dacomo:~/loginteller$ aptitude show loginteller2

your terminal will show you the following message:

Package: loginteller2
Version: 0.1-1
New: yes
State: installed
Automatically installed: no
Priority: extra
Section: utilities
Maintainer: jobima@inf1-jobima
Architecture: amd64
Uncompressed Size: 24.6 k
Description: It tells current login name at the system



5- How to convert a  .deb package into a .rpm pacakage

According to
How to Convert DEB to RPM  (or RPM to DEB), if you want to convert a .deb package into a .rpm package you should

a) Install a software package called alien running:

dacomo@inf1-dacomo:~$ aptitude install alien

b) Run alien -r  package_name.deb to convert a deb file into a rpm file.

In the following example, firstly, alien is installed on the system, and secondly, alien converts loginteller_0.1-1_amd64.deb into loginteller-0.1-2.i386 rpm. Now, you can install loginteller on Red Hat, Fedora, SuSE or CentOS.

dacomo@inf1-dacomo:~$ sudo aptitude install alien
dacomo@inf1-dacomo:~/loginteller$ sudo alien -r loginteller_0.1-1_amd64.deb
loginteller-0.1-2.x86_64.rpm generated
dacomo@inf1-dacomo:~/loginteller$ ls -ls loginteller*
20 -rwxrwxr-x 1 root   root  16768 Apr 14 23:38 loginteller
 4 -rw-r--r-- 1 root   root   2408
Apr 14 23:38 loginteller_0.1-1_amd64.deb
12 -rw-r--r-- 1 root   root   9160
Apr 14 23:41 loginteller-0.1-2.x86_64.rpm
 4 -rw-rw-r-- 1 dacomo dacomo  451
Apr 14 20:40 loginteller.c

PRACTICAL EXERCISE

1- Build a tarball package called loginteller-1.01.tar.gz with loginteller.c, Makefile and README.
Write your personal information in Makefile and loginteller.c.
2-
Build
loginteller_0.1-1_amd.64.deb. Write your personal information in the Maintainer entry of the checkinstall form.
3-
Build loginteller2_0.1-1_amd.64.deb. Write your personal information in the Maintainer entry of the checkinstall form.
4-
Create a .rpm file for each .deb file created previously.
5-
Download the following source code: http://www.collados.org/asix1/m01/tu3/userinfo.c. Create a Makefile to compile, clean, install and uninstall userinfo on your system.
6- Build a .deb package called userinfo_0.3-2_amd64.deb with userinfo.c and the Makefile archive created in the previous question.
Write your personal information in the Maintainer entry of the checkinstall form.
7- Convert
userinfo_0.3-2_amd64.deb into a .rpm package.
8- Create a Makefile archive to install and uninstall script03.sh on your system. Build a new .deb package called script03_0.2-5_amd64.deb.
Write your personal information in the Maintainer entry of the checkinstall form.
9-
Download the following  code: http://www.collados.org/asix1/m01/tu3/fjeclot.tar.gz and:
    a) Modify Makefile to install and uninstall fjeclot.py.
    b) Create and install a new .deb package called fjeclot_0.1-1_amd64.deb with the following information:
         Maintainer: your_username@your_hostname --> Write your real username and hostname.
        Sumary: Python sample
        Name: fjeclot
        Version: 0.1
        Release: 1
        License: GPL
        Group: utilities
        Architecture: amd64
        Source location: fjeclot.py
        Requires: python-wxgtk3.0
        Provides: fjeclot.py
    c)
If your system shows any error message, read carefully the message and try to solve the problem installing the proper software. Check if the package has been installed on your system.
    d) Run fjeclot.
10- Save:
 
   * loginteller-1.01.tar.gz                    * loginteller_0.1-1_amd.64.deb       * loginteller2_0.1-1_amd.64.deb
    *
loginteller-0.1-2.x86_64.rpm        * loginteller2-0.1-2.x86_64.rpm      * userinfo_0.3-2_amd64.deb
     *
userinfo-0.3-3.x86_amd64.rpm           * script03_0.2-5_amd64.deb                   * fjeclot_0.1-1_amd64.deb
into a .tar.gz file.
Read carefully GENERAL CONDITIONS at the top of this web page in order to know what  the file name is.