Build RPM to just install files
Asked Answered
P

2

15

I need to build a RPM, with the sole purpose of installing a few fonts. I have read several tutorials about that, however everyone seems to suggests something different and I haven't been able to find something like a very basic setup to do that.

Is it possible to just reference the files within the %files section of the spec? I tried however, RMP always tries to find the files within the tmp directory. Do I need to add a specific build step that copies everything I need to the tmp directory?

Should these files go into the SOURCE or the BUILD directory when building the RPM? I have been finding a lot of different information on that. Some suggest to build a tarball that contains the files and place that under the SOURCE directory, however that seems kind of wrong, as font files are not actual source files to me.

Ideally, I would like to just put all the font files within the BUILD folder under a directory structure like ./usr/share/fonts/ and then reference that within the %file section of the SPEC and let rpm do its magic. Probably I am missing or misunderstanding something here.

Does the %files section always expect to find the source files within the tmp directory, or is there something wrong with my setup? I have created ~/.rpmmacros which contains

%_topdir             /Users/user/rpm

which is the root build directory and contains the BUILD, RPMS, SOURCES, SPECS and tmp directories.

I would be glad if someone could provide which are the least required items in the spec file to get that to work cleanly.

Edit

Following user3159253's suggestions, I am using the following spec file:

Name: test
Version: 1.0.0
Release: 1
Copyright: Copyright info
Group: Applications/System
BuildArch: noarch

%description
Brief description of software package.

%prep

%build

%install
mkdir -p %{buildroot}/usr/share/fonts
cp ./usr/share/fonts/* %buildroot/usr/share/fonts/

%clean

%files
/usr/share/fonts/*

I copied the fonts into the BUILD/usr/share/fonts/ directory. If I query the rpm for a list of files, all fonts are there. However, when I install the rpm, it complains about

/usr/share/fonts is needed by test-1.0.0-1.noarch

However, it doesn't matter if this directory exists or not, so I guess rpm is complaining that this resource is not listed in its database.

I have been able to fix this by changing the %file section to:

/usr/
/usr/share/
/usr/share/fonts/
/usr/share/fonts/*

However, I doubt that this is such a good idea. Is there a better way to fix this?

Psychodrama answered 4/2, 2014 at 15:50 Comment(0)
H
9

when you list files in %files section these files are expected to reside within %{buildroot} directory. As Fedora documentation says since Fedora 10 buildroot can't be redefined in the spec, so yes, you have to create a required filesystem hierarchy within %buildroot, copy there your font files and then mention them in %files:

...
%install

mkdir -p %{buildroot}/usr/share/fonts
cp /path/to/existing/MyFont.ttf %buildroot/usr/share/fonts/
...

%files
%defattr(0644, root,root)
/usr/share/fonts/*

your distribution probably has handy macros for standard font files locations, their proper registation in the system upon installation of the rpm etc, but most of these macros are vendor-specific. Also, you should copy your font files into SOURCES/ subdirectory and mention them in Source: (Source<N>:) tag in the rpm spec (just an example, a number can be any):

Name: myfonts
Summary: my fonts package
...
Source5: MyFont.ttf
...

Then you may use something like this in the %install section:

cp %{SOURCE5} %buildroot/usr/share/fonts/

instead of a full path to the MyFont.ttf.

Update: You're right about missing dependencies: this is not artifacts (files, directories etc) on the filesystem, this is records in the RPM db (in /var/lib/rpm). So to solve the problem you have to work with that DB.

So if you have unsatisifed dependencies in the generated RPM package you have two options:

  1. if you simply wish to have a convenient way to distribute few files w/o tight integration with standard system facilities (see below), then you may simply turn off all rpm automatic dependency calculations. Use AutoReqProv: no to completely disable all that stuff.
  2. However you may need to build a package with a better integration with the rest of the OS. For example, fonts may need a registration within appropriate system facilities, e.g. fontconfig. Unfortunately, different Linux rpm distributions have slightly different, eh-hm, customs regarding that. Actually you have to check how this process is organized in your distribution in already existing font packages. You may take a suitable source rpm package (check http://rpmfind.net or http://rpm.pbone.net RPM search engines), extract its .spec-file and study how %prein, %postin, %preun and %postun section of the spec are organized. Obviously, font packages usually carry -fonts- in their name :)

Afterall, you may display dependencies and provides of an uninstalled rpm package with rpm --query --requires --package </path/to/file.rpm> and rpm --query --provides --package </path/to/file.rpm>. Installed packages' deps are shown with rpm --query --requires <rpm_name> and so on.

Hutto answered 4/2, 2014 at 16:14 Comment(6)
Thanks, at least I got to build the rpm with all the files in it, however it still fails. I have updated my question. Hopefully you can have a look at it.Psychodrama
Updated the answer. Hope it helps.Hutto
Thanks a lot. AutoReqProv: no should be sufficient as no one actually will use that rpm to install the fonts. Just using it to distribute the files via puppet. Registering the fonts will likely be easier with puppet then.Psychodrama
The problem for me is that there are numerous different paths which the .spec file might be referring to: 1.) local file system. 2.) rpmbuild/BUILD before calling rpmbuild. 3.) rpmbuild/SOURCES before calling rpmbuild. 4.) rpmbuild/BUILDROOT after rpmbuild has copied files to it. 5.) rpmbuild/? within built RPM. 6.) On the machine where the RPM is being installed. The syntax for %files, %install, etc. and the documentation which I've found assumes you know which of these paths its referring to. I'm only able to determine the specifics by experimenting.Aweather
Generally, all files within the %files section refer to files in a buildroot (%buildroot macro or outdated BuildRoot: tag). The only exception is files marked as %doc — they are taken by the rpmbuild engine right from rpmbuild/BUILD/<packagename>-<packageversion> and copied to %buildroot/usr/share/doc/<packagename>-<packageversion>.Hutto
just some info here: %install is only run when creating a package, not when the end-user installs the package. a bit misleading but thats how it isNeela
K
5

As an answer for your edited question, the following might be the answer you seek:

Name: test
Version: 1.0.0
Release: 1
Copyright: Copyright info
Group: Applications/System
BuildArch: noarch

%description
Brief description of software package.

%prep

%build

%install
mkdir -p %{buildroot}/
cp -r ./* %buildroot/

%clean

%files
/*

Here we consider every file in the BUILD directory to be a part of the package. This is done by placing /* under %files.

Hope this addresses your question correctly.

Knitted answered 21/7, 2017 at 12:58 Comment(1)
just some info here: %install is only run when creating a package, not when the end-user installs the package. a bit misleading but thats how it isNeela

© 2022 - 2024 — McMap. All rights reserved.