Building a Fedora RPM with “mock”

The mock program creates chroots and builds RPM packages in them. To install mock on your system, enter “yum install mock” in terminal (as the root user). Details for the mock project can be found here.
LoneWolf@LoneWolf:~$ su –
root@LoneWolf:~# yum install mock 

You must now add your user account to the mock group in order to run the software as a regular user. It is not good practice to build RPMS as the “root” user because there is a chance that you could compromise your OS installation; building RPM packages should never be performed as root. It should also be noted that the recommended practice is to create a new “build” user to run mock as there are security considerations to running as your regular user account. If you are concerned with security, create a new user with: “useradd -G groupname username“, and run mock as this user. To add your regular username to the mock group, enter the following command in terminal as root: “usermod -a -F groupname username“.
root@LoneWolf:~# usermod -a -G mock LoneWolf

There are problems associated with running mock with SELinux; an SELinux policy module can be installed as outlined here (Under the heading “Using Mock with SELinux). Execute the following commands to install this module:
mkdir /root/selinux.local
cd /root/selinux.local

wget http://fedoraproject.org/w/uploads/2/2f/PackageMaintainers_MockTricks_mock.if
wget http://fedoraproject.org/w/uploads/7/73/PackageMaintainers_MockTricks_mock.fc
wget http://fedoraproject.org/w/uploads/0/0b/PackageMaintainers_MockTricks_mock.te

yum -y install selinux-policy-devel checkpolicy
make -f /usr/share/selinux/devel/Makefile

Change to the user account you will use to run mock, and run the command:
mock -r fedora-your-distribution_releaseyour_arch /path/to/SRPM
Use the SRPM that you created as outlined in the post “Building a Fedora RPM“.

root@LoneWolf:selinux.local# logout
LoneWolf@LoneWolf:~$ mock -r fedora-14-x86_64 rpmbuild/SRPMS/less-418-1.fc14.src

This resulted in the following error :(…
checking for working terminal libraries… Cannot find terminal libraries – configure failed
error: Bad exit status from /var/tmp/rpm-tmp.6ua9eg (%build)
Since:
“Package ncurses-devel-5.7-9.20100703.fc14.x86_64 already installed…”
“Package ncurses-5.7-9.20100703.fc14.x86_64 already installed…”
“Package gcc-4.5.1-4.fc14.x86_64 already installed…”
I’ll have to figure out which library it is looking for.

Going back and executing “rpmbuild -ba list.spec” in the SPECS directory yielded this:
Requires(rpmlib):
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires:
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
libtinfo.so.5()(64bit)
rtld(GNU_HASH)

A quick search of the above entries at Linux Packages Search narrowed down the packages needed. This meant adding these two lines to the less.spec file:
BuildRequires:  kobo, kobo-rpmlib
Requires: glibc, ncurses-libs
This generated another error message after another rpmbuild -ba less.spec:

LoneWolf@LoneWolf:SPECS$ rpmlint ../RPMS/x86_64/less-418-1.fc14.x86_64.rpm
less.x86_64: E: explicit-lib-dependency ncurses-libs
less.x86_64: W: spurious-executable-perm /usr/share/doc/less-418/COPYING
less.x86_64: W: spurious-executable-perm /usr/share/doc/less-418/INSTALL
less.x86_64: W: spurious-executable-perm /usr/share/doc/less-418/LICENSE
1 packages and 0 specfiles checked; 1 errors, 3 warnings.
Shortening the Requires: entry to
Requires: glibc and rebuilding AGAIN eliminated this error.

As it turned out, the packages: glibc and ncurses-libs were already installed but the packages: kobo and kobo-rpmlib were not.
root@LoneWolf:~# yum -y install kobo kobo-rpmlib
LoneWolf@LoneWolf:SPECS$ mock -r fedora-14-x86_64 ../SRPMS/less-418-1.fc14.src.rpm
ERROR: Exception(../SRPMS/less-418-1.fc14.src.rpm) Config(fedora-14-x86_64) 0 minutes 44 seconds
checking for working terminal libraries… Cannot find terminal libraries – configure failed

After adding ncurses-devel to the BuildRequires section in my SPEC file, the build for “less” finally executed without error. It should be noted that because mock runs in a chroot environment, it does not have access to system libraries, unless they are included in the BuildRequires section of your .spec file.

The build for gawk went rather smoothly after applying the knowledge learned from building the less package.

Next topic: Building an RPM with koji

Advertisements

About gr8can8dian

Certified Linux geek.
This entry was posted in SBR600. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s