RPM Build Steps
RPM Build Steps
$ tree rpmbuild/
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS
BUILD - this is the folder where all of the files go which are created during a build
of the package you want to create
RPMS / SRPMS - If your build is successful this is the folder there the final rpm
file will be created. The SRPMS folder only contains source rpm.
SOURCES - This is the folder where you want to put the source tar file or/and
additional files such as init.d/systemd files.
SPECS - The SPECS folder is where your spec-file is located. A spec file is basically
a set of instructions on how to build the rpm package. I will explain the layout of
the spec-file in detail.
-------------
THE SPECFILE:
If there was one thing that you should know about creating a rpm it’s how to
write the spec file. As I wrote earlier a spec file consists of instructions on how
to package the software into an rpm and how it should be installed on the OS.
Not only that but also information about the package/software such as version
and licence.
Name, Version, Release - Should be pretty straight forward. Name the package,
it’s version and it’s release (dist is a macro that will translate to the red-hat
flavour dist you build on).
Group, Licence, URL, Source0 - Same here, this is also pretty basic stuff. Group
is used to categorize the package. If unsure take a look at /usr/share/doc/rpm-
4.8.0/GROUPS to see the full list of available groups. Next we have licence which
should be included, if for example you are packaging Elasticsearch you should
write that corresponding licence in your spec-file. Source0 is important, here
you write the name of the source tar file in the SOURCES directory. You can write
multiply Source in the specfile like this; Source0, Source1, Source2 and so on.
You would do this if you want to point to a startscript, logrotate or libs that you
don’t want to inclide in the source tar file.
You might noticed we didn’t cover the %prep and %setup definitions. We will
cover them shortly but first let’s talk about macros.
-------------
[InstallMedia-AppStream]
name=Red Hat Enterprise Linux 8 - AppStream
metadata_expire=-1
gpgcheck=1
enabled=1
baseurl=file:///mnt/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
----------
%description
Create a local yum repo file in /etc/yum.repos.d/ directory.
%prep
%setup -q
%install
mkdir -p "$RPM_BUILD_ROOT"
cp -R * "$RPM_BUILD_ROOT"
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
/etc/yum.repos.d/RHEL8local.repo
%changelog
* Fri Feb 25 2022 Vikas Nehra
-
-------------
$ cd
$ rpmbuild -v -bb rpmbuild/SPEC/localrepo.spec
$ rpm -qpl rpmbuild/RPMS/noarch/localrepo-1-0.noarch.rpm
$ exit
# rpm -ivh /home/vikasnehra/rpmbuild/RPMS/noarch/localrepo-1-
0.noarch.rpm
# rpm -qa | grep localrepo
# ls /etc/yum.repos.d/
# yum repolist all
# cat /etc/yum.repos.d/RHEL8local.repo
# mount /dev/sr0 /mnt
# yum install -y httpd vsftpd ftp samba
-------------
tree rpmbuild/
rpmbuild/
├── BUILD
│ └── localrepo-1
│ └── etc
│ └── yum.repos.d
│ └── RHEL8local.repo
├── BUILDROOT
├── RPMS
│ └── noarch
│ └── localrepo-1-0.noarch.rpm
├── SOURCES
│ ├── localrepo-1
│ │ └── etc
│ │ └── yum.repos.d
│ │ └── RHEL8local.repo
│ └── localrepo-1.tar.gz
├── SPECS
│ └── localrepo.spec
└── SRPMS