SM1: Open-source operating systems ASIX/DAW/DAM-1 Task A13: How to share and install software using  tarball and .deb packages 24-02-26

GENERAL CONDITIONS

DOCUMENTATION

a) Installing software via tarball files
b) Installing software via tarball files with the help of a Makefile
c) Installing software via a .deb software package and a package manager
d) Installing software via repository servers
PART I - CREATING TARBALL SOFTWARE PACKAGES

1.1- How to build a tarball software package from a program made of a single source code

Step 1) Source code development

We are going to develop a software that shows us our login name at system. Follow these steps:

1- Create a project directory 2- Create the source Code 4- Write a C program that retrieves and displays the system login name.

/* loginteller.c
 * Based on monousuar.c at http://www.binefa.net/gnu/gcc/processos/Informacio_d_usuari.html
 * www.binefa.cat
 * 20260223
*/
#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);
}

5- Compile the Program

gcc loginteller.c -o loginteller

6- Run the Program

./loginteller

The expected output is:
Your login name at the system is: your_username

NOTE: The displayed username depends on your system account.


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 and linking the source code
b) Cleaning binary files
c) Installing binary files on your system
d) Uninstalling binary files on your system

Start Geany and write the following Makefile:

############################################################################
# Makefile for building: loginteller
# 20260223 - www.binefa.cat
############################################################################

CC              = gcc
CFLAGS          = -Wall -Wextra -O2
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE        = rm -f

SOURCES   = loginteller.c
DESTDIR   = /usr/local/bin
TARGET    = loginteller

$(TARGET): $(SOURCES)
	$(CC) $(CFLAGS) -o $(TARGET) $(SOURCES)

clean:
	$(DEL_FILE) $(TARGET)

install: $(TARGET)
	$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)

uninstall:
	$(DEL_FILE) $(DESTDIR)/$(TARGET)

Now, you can easily:

a) Compile loginteller.cb> 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) 2026, 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:

tar cfz loginteller-1.01.tar.gz loginteller.c Makefile README



1.2- How to build a tarball software package from a program made of multiple sources codes

Step 1) Source code development

We are going to develop a software that shows us our login name at system. Follow these steps:

1- Create a project directory 2- Create a file called login.c with the following source code:

// login.c
// login.c gets the user's login username
// jobima & dacomo
// 20260223

#include <stdio.h>
#include <unistd.h>    // getlogin()
#include <stdlib.h>    // exit()

void showLogin(){
    char *szLogin;

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

3- Create a file called uid.c with the following source code:

// Program name: uid.c
// uid.c gets the user's UID number
// Authors: jobima & dacomo
// Date: 20260223

#include <stdio.h>
#include <unistd.h>    // getlogin()

void showUID(){
    int iUID;

    iUID = getuid();
    printf("Your UID number at the system is : %i\n",iUID);
}

4- Create a file called loginteller2.h with the following headers defined:

// Header name: loginteller2.h
// Header required for loginteller2.c
// Authors: jobima & dacomo
// Date: 20260223

#ifndef LOGINTELLER2_H
#define LOGINTELLER2_H
void showLogin();
void showUID();
#endif

5- Create a file called loginteller2.c with the following source code:

// Program name: loginteller2.c
// Authors: jobima & dacomo
// loginteller shows the user's login name and UID number
// Date: 20260223

#include "loginteller2.h"

int main(){
    showLogin();
    showUID();

    return 0;
}


Step 2) Creating a Makefile archive


############################################################################
# Makefile for building: loginteller2
# jobima and dacomo
# 20260223
############################################################################
#
####### Compiler
CC              = gcc
####### Compiler options
CFLAGS          = -Wall -c
LFLAGS          = -Wall -o
####### Installing and uninstalling programs and options
INSTALL_PROGRAM = install -p -m 755
DEL_PROGRAM     = rm -f
####### Files and directories
SOURCES   = loginteller2.c login.c uid.c
DEPS      = loginteller2.h
OBJECTS   = loginteller2.o login.o uid.o
DESTDIR   = /usr/bin
TARGET    = loginteller2
####### Compilation, linking and installing. Be careful, you have to write a TAB character at the beginnig of each command. Do not write whitespace characters.
%.o: %.c $(DEPS) $(SOURCES)
	$(CC) $(CFLAGS) $(SOURCES)
loginteller2:$(OBJECTS)
	$(CC) $(OBJECTS) $(LFLAGS) $(TARGET)
install:$(TARGET)
	$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)
####### Uninstalling and cleaning. Be careful, you have to write a TAB character at the beginnig of each command. Do not write whitespace characters.clean:
clean:$(TARGET) $(OBJECTS)
	$(DEL_PROGRAM) $(TARGET) $(OBJECTS)
uninstall:
	$(DEL_PROGRAM) $(DESTDIR)/$(TARGET)

Now, you can easily:

a) Compile and link the sources codes and headers running the following command: make loginteller2
b) Install a binary on your system running as a sudo user the following command: make install
b) Clean old binaries and object files running the following command: make clean
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:

********************************************
*                                          *
* loginteller2 v1.01                       *
* Copyright (C) 2026, jobima & dacomo      *
*                                          *
********************************************

Welcome to the loginteller2 program!  This program, once installed as
/usr/local/bin/loginteller2,  tells current uid and login name at the system.


SOURCES
=========

Web:      http://www.fjeclot.cat/software/utils/loginteller2/
FTP:      ftp://ftp.fjeclot.cat/pub/utils/loginteller2.tar.gz


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

Installation of loginteller2  is quite easy.   Simply follow these steps:

1. Building:

       # make loginteller2

2. Installing:

       # sudo make install

3. You are finished.


REMOVAL AND CLEANING
====================

Removal and cleaning of loginteller2  is quite easy as well.   Simply follow these steps:

1. Uninstalling:

       # sudo make uninstall

2. Cleaning :

       # make clean

3. You are finished.


LICENSE
=======

The  loginteller2 program  is  distributed  under the  terms  of the  GNU
General Public  License.  The  copyright on this  program belongs  to XXX
YYY.  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:   feedback@fjeclot.cat



Step 4) Creating a .tar.gz file

Run the following command:

tar cfz loginteller2-1.01.tar.gz loginteller2.c login.c uid.c loginteller2.h Makefile README



PART II - CREATING .deb PACKAGES

2.1- Installing checkinstall

In order to build a .deb package you need a tool called checkintall installed on your system. Run the following commands to install checkintall:

sudo aptitude update
sudo aptitude install checkinstall

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

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

and run again the commands to install checkintall.

2.2- How to build a .deb software package to share and install a single source code program

We are going to create a .deb software package for loginteller., which was developed in Part I - section 1.1, following these steps:

a) Gain access to the project directory.

b) Check that loginteller.c, Makefile and README exist. If they do not exist then, you have to create them. Remember: loginteller.c, Makefile and README have to be stored in the directory project.

c) If you had installed loginteller from a tarball package then, uninstall the and clean the products of the last building running:

make uninstall
make clean
	

d) Run checkinstall (in this example, my username is dacomo, my computer's hostname is inf1-dacomo and the project's directory is ~/loginteller):

checkinstall --install=no --deldesc=yes --backup=no

And the systems shows the following form:

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]: 
At the moment press n to avoid the creation of an additional set of package docs.

e)Now, write a description for the package:
Please write a description for the package.
End your description with an empty line or EOF.
>> <-- Write here: It tells current login name at the system
>> <-- Press Enter
f) Finally, build a .deb package with the following values:
*****************************************
**** 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.fjeclot.net  

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: [ 20260224 ]
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:
>> 1.01

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

**********************************************************************
g) At this moment a new .deb package loginteller_1.01-1_amd.64.deb has been build in your projecte directory. Check that the new package has been created.

h) Install loginteller_1.01-1_amd64.deb on your system running:

sudo dpkg -i loginteller_1.01-1_amd64.deb

And your system shows:
[sudo] password for dacomo: <-- write your password 
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) ...
...
....
i) Now, run the following command:

aptitude search loginteller

and your terminal will show the following message:
i    loginteller                - It tells current login name at the system
j) Finally, run the following command:

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
k) Now, you have successfully built and installed a new .deb package on your system.

l) If you want to check if your program works, run:

loginteller

and your terminal will show you the following message:
Your login name at the system is: dacomo
2.3- How to uninstall a .deb software package

a) If you want to remove loginteller from your system run the following command:

sudo  dpkg  -r  loginteller

and the sistem will show the following message:
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) 
b)If you want to reinstall loginteller, run again:

sudo  dpkg  -i  loginteller_1.01-1_amd64.deb

2.4- How to build a .deb software package to share and install a multiple source code program

We are going to create a .deb software package to install loginteller2b>, which was developed in Part I - section 1.2 following these steps:

a) Gain access to the project directory.

b) Check that login.c, uid.c, loginteller2.h, loginteller2.c, Makefile and README exist. If they do not exist then, you have to create them. Remember: loginteller2.c, loginteller2.h, login2.c, uid.c, Makefile and README have to be stored in the directory project.

c) If you had installed loginteller2 from a tarball package then, uninstall the and clean the products of the last building running:

make uninstall
make clean	

d) Run checkinstall:

checkinstall --install=no --deldesc=yes --deldoc=yes --delspec=no -d 0 --backup=no

And the systems shows the following form:
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]:
Press y to create an additional set of package docs.

e)Now, write a description for the package:
Please write a description for the package.
End your description with an empty line or EOF.
>> <-- Write here: It tells current login name and UID number at the system
>> <-- Press Enter
f) Finally, build a .deb package with the following values:
*****************************************
**** 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.fjeclot.net 

This package will be built according to these values:

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

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

This package will be built according to these values:

0 -  Maintainer: [ dacomo@inf1-dacomo.fjeclot.net ]
1 -  Summary: [ It tells current login name and UID number at the system ]
2 -  Name:    [ loginteller2 ]
3 -  Version: [ 1.01 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ loginteller2 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Recommends: [ ]
12 - Suggests: [ ]
13 - Provides: [ loginteller2 ]
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 and UID number at the system ]
2 -  Name:    [ loginteller2 ]
3 -  Version: [ 1.01 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ utilities ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ loginteller2 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Recommends: [ ]
12 - Suggests: [ ]
13 - Provides: [ loginteller2 ]
14 - Conflicts: [  ]
15 - Replaces: [  ]

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

Installing with make install...

========================= Installation results ===========================
gcc -Wall -c loginteller2.c login.c uid.c
gcc loginteller2.c login.c uid.c -Wall -o loginteller2
install -p -m 755 loginteller2 /usr/bin

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

Copying documentation directory...
./
./README
chown: changing ownership of '/var/tmp/tmp.FehxWLeUDX/package//usr/share/doc/loginteller2/README': Operation not permitted
chown: changing ownership of '/var/tmp/tmp.FehxWLeUDX/package//usr/share/doc/loginteller2': Operation not permitted

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 doc-pak directory...OK

Deleting temp dir...OK


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

 Done. The new package has been saved to

 /home/dacomo/m01tu3p4/loginteller2/loginteller2_1.01-1_amd64.deb
 You can install it in your system anytime using:

      dpkg -i loginteller2_1.01-1_amd64.deb

**********************************************************************
g) At this moment a new .deb package loginteller2_1.01-1_amd.64.deb has been build in your projecte directory. Check that the new package has been created.

h) Install loginteller2_1.01-1_amd.64.deb running:

sudo dpkg -i loginteller2_1.01-1_amd64.deb

And your system shows:
[sudo] password for dacomo: <-- write your password 
Selecting previously unselected package loginteller2.
(Reading database ... 238295 files and directories currently installed.)
Preparing to unpack loginteller2_1.01-1_amd64.deb ...
Unpacking loginteller2 (1.01-1) ...
Setting up loginteller2 (1.01-1) ...
...
....
i) Now, run the following command:

aptitude search loginteller2

and your terminal will show the following message:
i    loginteller2                - It tells current login name and UID number at the system
j) Afterwards, run the following command:

aptitude show loginteller2

and your terminal will show you the following message:
Package: loginteller2
Version: 1.01-1
New: yes
State: installed
Automatically installed: no
Priority: extra
Section: utilities
Maintainer: dacomo@inf1-dacomo
Architecture: amd64
Uncompressed Size: 49.2 k
Description: It tells current login name and UID number at the system
k) Now, you have successfully built and installed a new .deb package on your system.

l) Also, since you selected the option to create and install the documentation package, your README file has been copied to the /usr/share/doc/loginteller2 directory. Please check it.

m)If you want to check if your program works run:

loginteller2

and your terminal will show you the following message:
Your login name at the system is: dacomo
Your UID number at the system is: 1000
NOTE: If you want to remove .deb from your system run the following command:

sudo  dpkg  -r  loginteller2

PRACTICAL EXERCISES

1-Create: 2- Creating a Makefile: 3- Creating a Makefile: 4- Creating a .deb package: 5- Creating a .deb package: 6- Send: loginteller-1.01.tar.gz, loginteller2-1.01.tar.gz, userinfo_2.07-4_amd64.deb and netshow_1.04-1_amd64.deb. Read the General Conditions to know how to send your files.