Building a simple RPM on Oracle Linux (RedHat) using rpm build

0

1

I want to make a RPM using a certain user, from a specified build directory location. The RPM contains multiple files or one gzip, and should copy those files to a preset location (so it should be relocatable).

I've been to the Fedora site and other tutorials out there (including Stack Overflow), but nothing seems to work. All I could get (at best) was just a src.rpm which gives an error trying to write in %sourcedir /usr/src/redhat/SOURCES for some reason.

All I want is one spec file that can create an RPM which can handle one gzip or multiple plain text files, unpack it/copy them to the preset location. The rpm build should generate a rpm file in RPM directory.

I'm not interested in other tools that create RPMs, but how to create one using rpm build.

Using RPM version 4.4.2.3

user127350

Posted 2013-11-25T20:47:15.477

Reputation:

Answers

1

There is going to be a tad more information than you asked for. I assume that the original question poster knows how rpmbuild works, but maybe someone else doesn't.

Simple procedure to create an RPM installing two files.

Create directory hierarchy for rpmbuild: mkdir -p ~/rpmbuild/{SPEC,SOURCES}.

Copy some example content to your your dummy RPM files (these are needed when using the SPEC file later on in this example): cp /etc/profile ~/rpmbuild/SOURCES/dummy.file && cp /etc/shells ~/rpmbuild/dummy.another.file.

Paste following into ~/rpmbuild/SPEC/dummyrpmfile.spec:

Summary:        A dummy RPM. Creates file /etc/dummy/file.
Name:           dummyrpmfile
Version:        0.1
Release:        1
Vendor:         Super User
Packager:       Super User
License:        GPL
Group:          System Environment/Base
BuildArch:      noarch
Source0:        dummy.file
Source1:        dummy.another.file
Prefix:         /etc/dummy    

%description
A dummy RPM. Creates file /etc/dummy/file. And also directory /etc/dummy.
Very cool package. You should install this. Oh, yes, and it also makes
/etc/dummy/another.file too.

%install
# create directory /etc/dummy
%{__install} -d -m0755 %{buildroot}/etc/dummy
# and copy the file from SOURCES/file to <buildroot>/etc/dummy
%{__install} -m 0644 %{SOURCE0} %{buildroot}/etc/dummy/file
%{__install} -m 0644 %{SOURCE1} %{buildroot}/etc/dummy/another.file

%files
/etc/dummy/file
/etc/dummy/another.file

Then run cd ~/rpmbuild && rpmbuild -ba SPEC/dummyrpmfile.spec.

This should produce a "noarch" RPM in case it's just data and such which doesn't have differ between 32-bit and 64-bit architectures for example. Results should be in ~/rpmbuild/RPMS/noarch/dummyrpmfile.rpm.

Help links: How Prefix works.

Sami Laine

Posted 2013-11-25T20:47:15.477

Reputation: 1 002

Update: The prefix tag is clearly documented here: http://www.rpm.org/max-rpm/s1-rpm-reloc-prefix-tag.html. I'll update your example to be more clearly about the prefix use.

– None – 2014-07-21T10:45:22.867

Thanks for your answer. One thing I don't see is how do you set the install location. I've read something about "Prefix". Can you include it in your example? Thanks. – None – 2013-12-23T10:07:40.487

You need to create the appropriate director structure into your build directory. In case you want your files end up in /home/foouser/bardir/bazdir/, then just make %{buildroot}/home/foouser/bardir/bazdir/ and go from there. I'm not sure if I understood your question correctly, though. – Sami Laine – 2013-12-30T11:08:51.113

I meant how to set up the rpm, so you can give the install path at install time, using rpm --prefix. – None – 2013-12-31T16:00:31.370

Now I read you. This comes from the top of my head as I don't have an opportunity to test it. But adding just Prefix: should do it and you can afterwards use rpm --relocate to change /usr/local to whatever you want in that example. More details is in http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch10s05.html .

– Sami Laine – 2013-12-31T18:08:23.377