Basics of RPM - anujajakhade/anuja GitHub Wiki
RPM (Red Hat Package Manager) is an default open source and most popular package management utility for Red Hat based systems like (RHEL, CentOS and Fedora). The tool allows users to install, update, uninstall, query, verify and manage system software packages in Unix/Linux operating systems. It includes compiled software programs and libraries needed by the packages. This utility only works with packages that built on .rpm format.
An RPM package uses the .rpm extension and is a bundle (a collection) of different files. It can contain the following:
* Binary Files
* Configuration Files
* Documentation Files
The name of every RPM package is comprised as follows:
<name>-<version>-<release>.<arch>.rpm
eg. containerd.io-1.5.2-3.s390x.rpm
* Executes the commands and macros mentioned in the prep section of the spec file.
* Checks the content of the file list
* Executes the commands and macros in the build section of the spec file. Macros from the file list is also executed at this step.
* Creates the binary package file
* Creates the source package file
* Once the RPM executes the above steps, it creates the binary package file and source package file.
RPM
command is used for installing, uninstalling, upgrading, querying, listing, and checking RPM packages on your Linux system.
sudo yum/ zypper install -y rpm-devel
* rpm -i - Install the rpm
* rpm -U - Delete existing rpm and install latest
* rpm -F - Update rpm only if it is already installed
* rpm -e - Erase/ Clear
* rpm -qa - Query against all installed packages, or a single installed package
* rpm -V - Verify the current status of the file against the information cataloged by RPM when the package was installed
rpmbuild
command is used to build a rpm using the spec file. For that we need to do yum / zypper install rpm-build.
rpm-build will automatically create the following directory structures that will be used during the RPM build.
root@powder1:/$HOME/rpmbuild/
βββ BUILD - This is where the temporary files are stored, moved around, etc. It is used as a scratch space to actually compile the software.
βββ RPMS - Directory holds RPM packages built for different architectures
βββ SOURCES - holds sources. This can be a simple script, a complex C project that needs to be compiled, a pre-compiled program, etc.Usually, the sources are compressed as .tar.gz or .tgz files.
βββ SPECS - It contains your spec file or filesβone spec file per RPM you want to build.
βββ SRPMS - A Source RPM package doesnβt belong to an architecture or distribution. The actual .rpm package build is based on the .src.rpm package.
Note: The above directory structure is for both CentOS and RedHat. For SuSE Enterprise Linux, the same folders will be under /usr/src/packages directory.
There are two types of RPM: a Source RPM, known as an SRPM, and a Binary RPM, which is the type of RPM that most people are familiar with. The Binary RPM does not have to include any binaries, or even any kind of executable code, it is only called Binary because RPM comes from a tradition of creating executable binaries from source code.
You'll need the following components
* Source code to package.
* SPEC file to build the RPM.
* Set up a directory hierarchy per the rpmbuild specifications.
* Place your source code and supplemental files in the proper locations in the hierarchy.
The spec file, short for specification file, defines all the actions the rpmbuild command should take to build your application, as well as all the actions necessary for the rpm command to install and remove the application. Each source RPM should have the necessary spec file for building a binary RPM.
policycoreutils.spec
# Copyright (c) 2021 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: policycoreutils
Version: 3.2
Release: 1%{?dist}
Group: System Environment/Base
Summary: policycoreutils package
License: GPLv3+
Source0: libsepol-3.2.tar.gz
Source1: policycoreutils-3.2.tar.gz
%description SPEC file to create a policycoreutils rpm
%configure
%install
mkdir -p %{buildroot}/
cp -r ./* %{buildroot}/
sudo zypper install -y gzip make gcc7 flex libbz2-devel libsemanage-devel gettext bison wget tar
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7
tar -xvf libsepol-3.2.tar.gz
cd libsepol-3.2
make CC=gcc
sudo make install
cd ..
tar -xvf libselinux-3.2.tar.gz
cd libselinux
make CC=gcc
sudo make install
cd ..
tar -xvf policycoreutils-3.2.tar.gz
cd policycoreutils-3.2
make CC=gcc
sudo make install
%clean
%files
/*
Build the rpm using the command
rpmbuild -bb policycoreutils.spec