M01:
Introduction to Operating Systems |
TU1: Installing specific purpose software
|
ASIX1
|
Prąctical Exercise 1: How to create a .deb and .rpm
package
|
22-04-2014 |
PRACTICAL EXERCISE 1: HOW TO CREATE A .deb
AND .rpm PACKAGE
GENERAL CONDITIONS
1-
Deadline: 10-05-2014.
2-
Send your report as a PDF
file 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 (Catalan): asix1_surname_name_m01tu03pr1.pdf
b2.) DAW1 (English): daw1_surname_name_m01tu03pr1.pdf
c) Subject:
c.1) ASIX1 (Catalan): asix1_surname_name_m01tu03pr1
c.2) DAW1 (English): 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.
DOCUMENTATION
D.1) 1st
part
This
practical exercise is about to explain how to develop a .deb file. At
the end of this 1st part you will got a
loginteller_0.1-1_i386.deb file able to be installed through GDebi.
Download
login-teller's
source code.
#include <stdio.h>
#include <unistd.h> // getlogin()
#include <stdlib.h> // exit()
int main(){
char *szNomAcces;
if((szNomAcces = getlogin())==NULL){
perror("getlogin");
exit(EXIT_FAILURE);
}
printf("Your login name at the system is : %s\n",szNomAcces);
return (0);
}
One way to compile it is :
fje@fje-ExtDisc:~/Documents/ISOL/uf3/login-teller$
gcc loginteller.c -o loginteller
Executing :
fje@fje-ExtDisc:~/Documents/ISOL/uf3/login-teller$
./loginteller
Your login name at the
system is : fje
Knowing its library dependencies :
fje@fje-ExtDisc:~/Documents/ISOL/uf3/login-teller$
ldd ./loginteller
linux-gate.so.1 => (0xb77d6000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7642000)
/lib/ld-linux.so.2 (0xb77d7000)
And removing :
fje@fje-ExtDisc:~/Documents/ISOL/uf3/login-teller$
rm loginteller
Another way to compile it is using make :
fje@fje-ExtDisc:~/Documents/ISOL/uf3/login-teller$
make
gcc loginteller.c -o
loginteller
Using this kind of 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
loginteller:
$(CC) $(SOURCES) $(CFLAGS) $(TARGET)
clean:
$(DEL_FILE) $(TARGET)
####### Install
install: $(TARGET)
$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)
# install -m 755 $(TARGET) $(DESTDIR)
uninstall:
$(DEL_FILE) $(DESTDIR)/$(TARGET)
# rm -f $(DESTDIR)/$(TARGET)
The way to make an
executable binary file using Makefile is : make
or make
loginteller. Being loginteller: a Makefile's label.
Cleaning binary files : make clean
Installing in the correct
path : make install
Uninstalling : make uninstall
Execute and remove loginteller binary file.
Making .deb file (it is needed source code + Makefile in same
directory)
using checkinstall
:
fje@fje-ExtDisc:~/Documents/ISOL/uf3/login-teller$
sudo checkinstall
[sudo] password for inf1:
checkinstall 1.6.2,
Copyright 2009 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@debian-m01 ]
1 - Summary: [ Package created with checkinstall 1.6.2 ]
2 -
Name: [ login ]
3 - Version: [ teller
]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 -
Group: [ checkinstall ]
7 - Architecture: [
i386 ]
8 - Source location:
[ login-teller ]
9 - Alternate source
location: [ ]
10 - Requires: [ ]
11 - Provides: [ login ]
12 - Conflicts: [ ]
13 - Replaces: [ ]
Enter a number to change
any of them or press ENTER to continue:
Modify menu using differents options until reach :
This package will be
built according to these values:
0
- Maintainer: [ root@debian-m01 ]
1
- Summary: [ It tells current login name at the system. Package created with checkinstall 1.6.2 ]
2
- Name: [ loginteller ]
3
- Version: [ 0.1 ]
4
- Release: [ 1 ]
5
- License: [ GPL ]
6
- Group: [ utilities ]
7
- Architecture: [ amd64 ]
8
- Source location: [ login-teller ]
9
- Alternate source location: [ ]
10 -
Requires: [ ]
11 -
Provides: [ loginteller ]
12 -
Conflicts: [ ]
13 -
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/fje/Documents/ISOL/uf3/login-teller/loginteller_0.1-1_i386.deb
You can remove it
from your system anytime using:
dpkg -r loginteller
**********************************************************************
At this moment loginteller package has been installed. To remove it
from your system : dpkg -r
loginteller
To install through terminal : dpkg
--install loginteller_0.1-1_amd64.deb.
To install from GUI : double click on loginteller_0.1-1_amd64.deb
through GDebi (screenshot at the top of this
webpage).
D.2) 2nd
part
This
practical exercise is about to explain how to develop a .deb file using
a bash script. Files
needed for this second part.
ldd
is a command to know library dependencies.
lddpkgs.sh
is a (very low speed) script
to know which packages are related to those library dependencies.
#!/bin/bash
# Based on http://rtfreesoft.blogspot.com/2009/12/ldd-package-finder-apt.html
# 20110426 - www.binefa.cat
if [ "$2" = "nocommonlib" ];then
COMMONLIBS='libc|libdl|dbg|lib64'
ldd $1|awk '{tmp ="basename "$1; tmp|getline bnso;system("apt-file find "bnso);close(tmp)}'|egrep -v $COMMONLIBS|awk -F':' '{print $1}'|sort|uniq
else
ldd $1|awk '{tmp ="basename "$1; tmp|getline bnso;system("apt-file find "bnso);close(tmp)}'|awk -F':' '{print $1}'|sort|uniq
fi
exit 0
Use of lddpkgs.sh :
./lddpkgs.sh
/usr/bin/gcalctool
being gcalctool
an executable binary file developed using GTK+
or
./lddpkgs.sh hola-mon
being hola-mon
an executable binary file (included in lddpkgs.tar.gz)
developed using Qt
A way to avoid common system
libraries at the final output list :
./lddpkgs.sh
/usr/bin/gcalctool nocommonlib
or
./lddpkgs.sh hola-mon
nocommonlib
A
.deb file in this case is thought to install the script in the proper
folder. This is the Makefile :
#############################################################################
# Makefile for building: lddpkgs.sh
# 20110426 - www.binefa.cat
#############################################################################
####### Files
DESTDIR = /usr/local/bin
TARGET = lddpkgs.sh
####### Install
install: $(TARGET)
install -m 755 $(TARGET) $(DESTDIR)
uninstall:
rm -f $(DESTDIR)/$(TARGET)
Making .deb file (it is needed script + Makefile in same directory)
using checkinstall
:
fje@fje-ExtDisc:~/Documents/ISOL/uf3/lddpkgs$
sudo checkinstall
There is a dependency in lddpkgs.sh script.
It is needed apt-file.
It should be fulfilled that apt-file
is required.
:
0 -
Maintainer: [ jbinefa@fje.edu ]
1 - Summary: [
lddpkgs.sh installer ]
2 -
Name: [ lddpkgs ]
3 - Version: [
20110426 ]
4 - Release: [ 1 ]
5 - License: [ BSD ]
6 -
Group: [ utilities ]
7 - Architecture: [
i386 ]
8 - Source location:
[ lddpkgs ]
9 - Alternate source
location: [ ]
10 - Requires: [ apt-file ]
11 - Provides: [ lddpkgs.sh
]
Once it has been installed
there is no need to use ./ because
lddpkgs.sh
has been copied at a directory present in PATH
environment variable. And it can be used at any
directory.
fje@fje-ExtDisc:~/Documents/ISOL/uf3/lddpkgs$ lddpkgs.sh hola-mon nocommonlib
libfreetype6
libglib2.0-0
libpng12-0
libqt4-dev
libqtcore4
libqtgui4
D.3) 3rd
part
How
to Convert DEB to RPM (RPM to DEB) Package Using Alien Command
Use alien -r
option to convert a deb file to rpm file. The following example
converts loginteller_0.1-1_i386 deb file to loginteller-0.1-2.i386 rpm
file. Once you generate the rpm file, you can install it on Red Hat, or
CentOS.
$ sudo aptitude install alien
$ sudo alien -r loginteller_0.1-1_i386.deb
tar: Mida del registre = 8
blocs
loginteller-0.1-2.i386.rpm
generated
$ ls loginteller* -ls
8 -rwxrwxr-x 1 jordi jordi
7281 2012-05-08 12:16 loginteller
4 -rw-r--r-- 1 root
root 2414 2012-05-08 11:37 loginteller_0.1-1_i386.deb
4 -rw-r--r-- 1 root
root 4076 2012-05-09 19:58 loginteller-0.1-2.i386.rpm
4 -rw-rw-r-- 1 jordi
jordi 462 2012-05-08 11:28 loginteller.c
PRACTICAL
EXERCISE
Previously it is needed to
install GDebi, alien, checkinstall, qt4-dev-tools and qtcreator packages from aptitude or synaptic.
1)
Uncompress uf3Ex.zip
and create an executable binary (qmake creates a Makefile and make
creates an executable binary if source code and Makefile exists).
Check if this executable running looks like this screen shot :
2)
Modify Makefile file to be able to do :
2.1)
make install
(It installs executable binary at /usr/local/bin)
2.2) make uninstall
(It removes executable binary from /usr/local/bin)
2.3) make clean
(It removes *.o, *.pro.user, ui_*,
moc_* files)
3)
Create a deb
file using
checkinstall.
3.1)
Modify Maintainer,
Summary, Version, License and Group parameters
3.2) To do a list with no common
library dependencies
3.2) Modify Requires parameter
3.3) .deb
file created without errors
4)
Install .deb file on your
Debian. Check if
it works properly.
5)
Install .deb
file on a Ubuntu. Check if it works
properly.
6) Create a .rpm file from .deb file
created previously
7)
Install .rpm file on a Fedora
machine.
Check if it works properly.