M01: Introduction to Operating Systems TU3: Installing specific purpose software
ASIX1
Pràctical Exercise 4: How to create .deb packages
3-05-2022

PRACTICAL EXERCISE 4: HOW TO CREATE .deb PACKAGES

GENERAL CONDITIONS

1- Deadline: 15-05-2022.
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
) Subject:
         b.1)
ASIX1: asix1_surname_name_m01tu03pr4
         b.2)
DAW1: daw1_surname_name_m01tu03pr4

DOCUMENTATION

1- How to install software on Debian and derivatives

a) Debian derivatives

b) Installing software via tarball files
c) Installing software via tarball files with the help of a Makefile

d) Installing software via a .deb software package and a package manager
e) Installing software via repository servers

2- How to build a simple tarball software package

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) Clean  old binaries and object files 
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-2021, 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 loginteller  is quite easy.   Simply follow these steps:

1. Building:

       # make loginteller

2. Installing:

       # sudo make install

3. You are finished.


REMOVAL
=======

Removal of loginteller  is quite easy as well.   Simply follow these steps:

1. Uninstalling:

       # sudo make uninstall

2. Cleaning (:

       # make clean

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$ checkinstall --install=no --deldesc=yes --backup=no

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]: n

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: [ 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: 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.fjeclot.net ]
1 -  Summary: [ It tells current login name at the system ]
2 -  Name:    [ loginteller ]
3 -  Version: [
20210513 ]
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
.fjeclot.net ]
1 -  Summary: [ It tells current login name at the system ]
2 -  Name:    [ loginteller ]
3 -  Version: [ 1.01 ]

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
.fjeclot.net ]
1 -  Summary: [ It tells current login name at the system ]
2 -  Name:    [ loginteller ]
3 -  Version: [ 1.01 ]
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

NOTE: The package will not be installed

Erasing temporary files...OK

Deleting temp dir...OK



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

 Done. The new package has been installed and saved to

 /home/dacomo/loginteller/loginteller_1.01-1_amd64.deb
 You can install it in your system anytime using:

      dpkg -i loginteller_1.01-1_amd64.deb

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

d) 
At this moment a new .deb package loginteller_1.01-1_amd.64.deb has been build in your working directory. Run the following command:

dacomo@inf1-dacomo:~/loginteller$ ls

and your terminal will show you the following files:


loginteller  loginteller_1.01-1_amd64.deb loginteller.c Makefile

e) Install
loginteller_1.01-1_amd64.deb running:

dacomo@inf1-dacomo:~/loginteller$ sudo dpkg -i loginteller_1.01-1_amd64.deb
[sudo] password for dacomo:
Selecting previously unselected package loginteller.
(Reading database ... 300676 files and directories currently installed.)
Preparing to unpack loginteller_1.01-1_amd64.deb ...
Unpacking loginteller (1.01-1) ...
Setting up loginteller (1.01-1) ...


Afterwards, run the following command:

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

and your terminal will show 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: 1.01-1
New: yes
State: installed
Automatically installed: no
Priority: extra
Section: utilities
Maintainer: dacomo@inf1-dacomo.fjeclot.net
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 
Reading database ... 300678 files and directories currently installed.)
Removing loginteller (1.01-1) ...
dpkg: warning: while removing loginteller, directory '/usr/local/bin' not empty so not removed
(NOTE:  Do not worry about any warning message) 

g) If you want to install loginteller through the terminal run again:  sudo  dpkg  -i  loginteller_1.01-1_amd64.deb

PRACTICAL EXERCISE

1-
Build:
2- Download the following source code: http://www.collados.org/asix1/m01/tu3/userinfo.c. Create:
     a) A Makefile to compile, clean, install and uninstall userinfo on your system.
     b) A README  file with information about  version (1.02), release (6), authors (write your personal information), a small explanation, sources, compiling, installing, removal, license and feedback.
     c)
A tarball package called userinfo-1.02.tar.gz
     d) Build a .deb package called userinfo_1.02-6_amd64.deb with userinfo.c and the Makefile archive created in the previous question.
Write your personal information in Maintener of the checkinstall form.

3- Download the following source code: http://www.collados.org/asix1/m01/tu3/triangle.c. Create:
     a) A Makefile to compile, clean, install and uninstall triangle on your system.
     b) A README  file with information about  version (2.17), release (3), authors (write your personal information), a small explanation, sources, compiling, installing, removal, license and feedback.
     c
) Build a .deb package called triangle_2.17-3_amd64.deb with triangle.c and the Makefile archive created in the previous question. Write your personal information in  Maintainer of checkinstall form

4- Save:
     * loginteller-1.01.tar.gz
     * loginteller_1.01-1_amd64.deb
  
  * userinfo_1.02.tar.gz
    * userinfo_1.02-6_amd64.deb
    * triangle_2.17-3_amd64.deb