| 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 |
/* 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.
############################################################################
# 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:
********************************************
* *
* 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
tar cfz loginteller-1.01.tar.gz loginteller.c Makefile README
// 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;
}
############################################################################
# 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:
********************************************
* *
* 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
tar cfz loginteller2-1.01.tar.gz loginteller2.c login.c uid.c loginteller2.h Makefile README
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.
make uninstall
make clean
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.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 Enterf) 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.
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 systemj) 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 systemk) Now, you have successfully built and installed a new .deb package on your system.
loginteller
and your terminal will show you the following message:
Your login name at the system is: dacomo2.3- How to uninstall a .deb software package
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
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.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 Enterf) 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.
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 systemj) 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 systemk) Now, you have successfully built and installed a new .deb package on your system.
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: 1000NOTE: If you want to remove .deb from your system run the following command:
sudo dpkg -r loginteller2
PRACTICAL EXERCISES