Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 1 down vote accepted

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    

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.

# 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


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.

share|improve this answer
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. – user127350 Dec 23 '13 at 10:07
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 Dec 30 '13 at 11:08
I meant how to set up the rpm, so you can give the install path at install time, using rpm --prefix. – user127350 Dec 31 '13 at 16:00
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… . – Sami Laine Dec 31 '13 at 18:08
Update: The prefix tag is clearly documented here: I'll update your example to be more clearly about the prefix use. – user127350 Jul 21 '14 at 10:45

You must log in to answer this question.