Créer un paquet RPM

Impossible de trouver une documentation simple pour créer un paquet RPM alors voici la mienne.

Le programme

Supposons le mini programme suivant qu'on veut packager compilé pour une distribution rapide.

On est dans le répertoire $HOME/src/hello-world

hello-world.c

1#include <stdio.h>
2int main() {
3   printf("Hello fancy RPM Package\n");
4   return 0;
5}

Makefile

1all:
2	gcc -o hello-world hello-world.c
3
4install:
5	install -D hello-world /usr/local/bin/hello-world

Création du paquet RPM

Prérequis

1$ sudo dnf install rpmdevtools rpmlint

Création de l'arborescence de travail

1$ rpmdev-setuptree
2$HOME/rpmbuild/
3├── BUILD
4├── RPMS
5├── SOURCES
6├── SPECS
7└── SRPMS

Création du fichier SPECS/hello.spec décrivant le paquet

 1Name:           hello
 2Version:        0.0.1
 3Release:        1%{?dist}
 4Summary:        Simple hello world
 5BuildArch:      noarch
 6
 7License:        GPL
 8Source0:        %{name}-%{version}.tar.gz
 9
10Requires:       bash
11
12%description
13Demo RPM
14
15%prep
16%setup -q
17
18%clean
19rm -rf $RPM_BUILD_ROOT
20
21%install
22rm -rf $RPM_BUILD_ROOT
23mkdir -p $RPM_BUILD_ROOT/%{_bindir}
24cp %{name}.sh $RPM_BUILD_ROOT/%{_bindir}
25
26%files
27%{_bindir}/%{name}.sh
28
29%changelog
30* Wed Jan 29 2025 vagrant
31-

Compilation

 1$ rpmbuild -ba ~/rpmbuild/SPECS/hello.spec
 2setting SOURCE_DATE_EPOCH=1738108800
 3Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.0CErfa
 4+ umask 022
 5+ cd /home/vagrant/rpmbuild/BUILD
 6+ cd /home/vagrant/rpmbuild/BUILD
 7+ rm -rf hello-0.0.1
 8+ /usr/bin/tar -xof /home/vagrant/rpmbuild/SOURCES/hello-0.0.1.tar.gz
 9+ STATUS=0
10+ '[' 0 -ne 0 ']'
11+ cd hello-0.0.1
12+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
13+ RPM_EC=0
14++ jobs -p
15+ exit 0
16Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.P4fUUo
17+ umask 022
18+ cd /home/vagrant/rpmbuild/BUILD
19+ '[' /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64 '!=' / ']'
20+ rm -rf /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64
21++ dirname /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64
22+ mkdir -p /home/vagrant/rpmbuild/BUILDROOT
23+ mkdir /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64
24+ cd hello-0.0.1
25+ rm -rf /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64
26+ mkdir -p /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64//usr/bin
27+ cp hello.sh /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64//usr/bin
28+ /usr/bin/find-debuginfo -j2 --strict-build-id -m -i --build-id-seed 0.0.1-1.el9 --unique-debug-suffix -0.0.1-1.el9.aarch64 --unique-debug-src-base hello-0.0.1-1.el9.aarch64 --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 50000000 --remove-section .gnu.build.attributes -S debugsourcefiles.list /home/vagrant/rpmbuild/BUILD/hello-0.0.1
29+ '[' '%{buildarch}' = noarch ']'
30+ QA_CHECK_RPATHS=1
31+ case "${QA_CHECK_RPATHS:-}" in
32+ /usr/lib/rpm/check-rpaths
33+ /usr/lib/rpm/check-buildroot
34+ /usr/lib/rpm/redhat/brp-ldconfig
35+ /usr/lib/rpm/brp-compress
36+ /usr/lib/rpm/redhat/brp-strip-lto /usr/bin/strip
37+ /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip
38+ /usr/lib/rpm/redhat/brp-python-bytecompile '' 1 0
39+ /usr/lib/rpm/brp-python-hardlink
40+ /usr/lib/rpm/redhat/brp-mangle-shebangs
41Processing files: hello-0.0.1-1.el9.noarch
42Provides: hello = 0.0.1-1.el9
43Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
44Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64
45Wrote: /home/vagrant/rpmbuild/SRPMS/hello-0.0.1-1.el9.src.rpm
46Wrote: /home/vagrant/rpmbuild/RPMS/noarch/hello-0.0.1-1.el9.noarch.rpm
47Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.l0wSQu
48+ umask 022
49+ cd /home/vagrant/rpmbuild/BUILD
50+ cd hello-0.0.1
51+ rm -rf /home/vagrant/rpmbuild/BUILDROOT/hello-0.0.1-1.el9.aarch64
52+ RPM_EC=0
53++ jobs -p
54+ exit 0

Arborescence après création des paquets (source+binaire)

 1tree rpmbuild/
 2rpmbuild/
 3├── BUILD
 4│   └── hello-0.0.1
 5│       ├── debugfiles.list
 6│       ├── debuglinks.list
 7│       ├── debugsourcefiles.list
 8│       ├── debugsources.list
 9│       ├── elfbins.list
10│       └── hello.sh
11├── BUILDROOT
12├── RPMS
13│   └── noarch
14│       └── hello-0.0.1-1.el9.noarch.rpm
15├── SOURCES
16│   └── hello-0.0.1.tar.gz
17├── SPECS
18│   └── hello.spec
19└── SRPMS
20    └── hello-0.0.1-1.el9.src.rpm
21
228 directories, 10 files

Installation du paquet

 1$ sudo dnf install ./rpmbuild/RPMS/noarch/hello-0.0.1-1.el9.noarch.rpm -y
 2Extra Packages for Enterprise Linux 9 - aarch64                                                106 kB/s |  14 kB     00:00
 3Dependencies resolved.
 4===============================================================================================================================
 5 Package                   Architecture               Version                           Repository                        Size
 6===============================================================================================================================
 7Installing:
 8 hello                     noarch                     0.0.1-1.el9                       @commandline                     6.5 k
 9
10Transaction Summary
11===============================================================================================================================
12Install  1 Package
13
14Total size: 6.5 k
15Installed size: 29
16Is this ok [y/N]: y
17Downloading Packages:
18Running transaction check
19Transaction check succeeded.
20Running transaction test
21Transaction test succeeded.
22Running transaction
23  Preparing        :                                                                                                       1/1
24  Installing       : hello-0.0.1-1.el9.noarch                                                                              1/1
25  Verifying        : hello-0.0.1-1.el9.noarch                                                                              1/1
26
27Installed:
28  hello-0.0.1-1.el9.noarch
29
30Complete!

Désinstallation du paquet

 1$ sudo dnf remove hello -y
 2Dependencies resolved.
 3===============================================================================================================================
 4 Package                   Architecture               Version                          Repository                         Size
 5===============================================================================================================================
 6Removing:
 7 hello                     noarch                     0.0.1-1.el9                      @@commandline                      29
 8
 9Transaction Summary
10===============================================================================================================================
11Remove  1 Package
12
13Freed space: 29
14Is this ok [y/N]: y
15Running transaction check
16Transaction check succeeded.
17Running transaction test
18Transaction test succeeded.
19Running transaction
20  Preparing        :                                                                                                       1/1
21  Erasing          : hello-0.0.1-1.el9.noarch                                                                              1/1
22  Verifying        : hello-0.0.1-1.el9.noarch                                                                              1/1
23
24Removed:
25  hello-0.0.1-1.el9.noarch
26
27Complete!

Ressources

comments powered by Disqus