RH401: Create a custom RPM spec file and build a binary RPM from source code

if you are going to create RPMs, you definitely need gcc

[root@satellite ~]# yum -y install gcc openssl-devel

create a build user

[root@satellite ~]# useradd rpmbuild
[root@satellite ~]# su - rpmbuild

setup build user's environment

[rpmbuild@satellite ~] sudo yum install rpmdevtools
[rpmbuild@satellite ~] rpmdev-setuptree

this takes care of .rpmmacros population and rpmbuild directory tree creation

generate a spec file:

[rpmbuild@satellite ~]$ rpmdev-newspec test.spec
test.spec created; type minimal, rpm version >= 4.9.

edit the values accordingly. documentation below might help:

[rpmbuild@satellite ~]$ vi /usr/share/doc/rpm-4.9.1.3/spec

let's try to compile fping as an exercise. this package comes with its own spec file, but let's make our own:

[rpmbuild@satellite ~]$ cd rpmbuild/SOURCES/
[rpmbuild@satellite SOURCES]$ wget http://fping.sourceforge.net/download/fping.tar.gz
...
[rpmbuild@satellite SOURCES]$ ls
fping.tar.gz
[rpmbuild@satellite SOURCES]$ tar -zxvf fping.tar.gz; mv -f fping-2.4b2_to fping-2.4b2
[rpmbuild@satellite SOURCES]$ tar -zcvf fping-2.4b2.tar.gz fping-2.4b2
[rpmbuild@satellite SOURCE]$ cd
[rpmbuild@satellite ~]$ rpmdev-newspec fping.spec
Skeleton specfile (minimal) has been created to "fping.spec".
(edit the spec file to taste)
[rpmbuild@satellite ~]$ rpmbuild -bb fping.spec
...
error: Installed (but unpackaged) file(s) found:
   /usr/sbin/fping
   /usr/share/man/man8/fping.8.gz
...
(edit the spec file and add these files under %files)

[rpmbuild@satellite ~]$ rpmbuild -bb fping.spec
Wrote: /home/rpmbuild/rpmbuild/RPMS/x86_64/fping-2.4b2-1.el6.x86_64.rpm

[rpmbuild@satellite ~]$ rpm -qpi /home/rpmbuild/rpmbuild/RPMS/x86_64/fping-2.4b2-1.el6.x86_64.rpm
Name        : fping                        Relocations: (not relocatable)
Version     : 2.4b2                             Vendor: (none)
Release     : 1.el6                         Build Date: Thu 10 May 2012 12:48:59 AM SGT
Install Date: (not installed)               Build Host: satellite.localdomain
Group       : Application/System            Source RPM: fping-2.4b2-1.el6.src.rpm
Size        : 36298                            License: GPL
Signature   : (none)
URL         : http://ftp.gnu.org/gnu/fping/fping-2.4b2.tar.gz
Summary     : fping compiled on the satellite server
Description :
fping compiled on the satellite server
as an exercise for EX401

we will need to sign this package later before we can upload to the satellite server

No comments:

Post a Comment