构建 RPM 以安装文件 [英] Build RPM to just install files

查看:45
本文介绍了构建 RPM 以安装文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建一个 RPM,其唯一目的是安装一些字体.我已经阅读了一些关于此的教程,但是每个人似乎都提出了不同的建议,我一直无法找到类似非常基本的设置来做到这一点.

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.

是否可以只引用规范的 %files 部分中的文件?但是我试过了,RMP 总是试图在 tmp 目录中查找文件.我是否需要添加一个特定的构建步骤来将我需要的所有内容复制到 tmp 目录?

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?

在构建 RPM 时,这些文件应该进入 SOURCE 还是 BUILD 目录?我一直在寻找很多不同的信息.有些人建议构建一个包含文件的 tarball 并将其放在 SOURCE 目录下,但这似乎有点错误,因为字体文件对我来说并不是真正的源文件.

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.

理想情况下,我只想将 BUILD 文件夹中的所有字体文件放在像 ./usr/share/fonts/ 这样的目录结构下,然后在 %file 中引用它 部分,让 rpm 发挥它的魔力.可能我在这里遗漏或误解了一些东西.

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.

%files 部分是否总是希望在 tmp 目录中找到源文件,还是我的设置有问题?我创建了 ~/.rpmmacros 其中包含

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

这是根构建目录,包含 BUILD、RPMS、SOURCES、SPECS 和 tmp 目录.

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.

编辑

按照 user3159253 的建议,我使用以下规范文件:

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/*

我将字体复制到 BUILD/usr/share/fonts/目录中.如果我在 rpm 中查询文件列表,则所有字体都在那里.但是,当我安装 rpm 时,它会抱怨

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

然而,这个目录是否存在并不重要,所以我猜 rpm 抱怨这个资源没有列在它的数据库中.

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.

我已经能够通过将 %file 部分更改为:

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?

推荐答案

当您在 %files 部分列出文件时,这些文件应该位于 %{buildroot} 目录中.正如 Fedora 文档所说,自从 Fedora 10 buildroot 不能在规范中重新定义,所以是的,您必须在 %buildroot 中创建所需的文件系统层次结构,将您的字体文件复制到那里,然后在 %files 中提及它们:

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/*

您的发行版可能有用于标准字体文件位置的方便的宏,它们在安装 rpm 时在系统中的正确注册等,但这些宏中的大多数是特定于供应商的.此外,您应该将字体文件复制到 SOURCES/子目录中,并在 rpm 规范中的 Source: (Source:) 标记中提及它们(只是一个示例,一个数字可以是任何):

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
...

然后你可以在 %install 部分使用类似的东西:

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

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

而不是 MyFont.ttf 的完整路径.

instead of a full path to the MyFont.ttf.

更新:您对缺少依赖项的看法是正确的:这不是文件系统上的工件(文件、目录等),而是 RPM 数据库中的记录(在/var/lib/rpm 中).所以要解决这个问题,你必须使用那个数据库.

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.

因此,如果您在生成的 RPM 包中有不满意的依赖项,您有两个选择:

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

  1. 如果您只是希望有一种方便的方式来分发少量文件,而无需与标准系统设施紧密集成(见下文),那么您只需关闭所有rpm代码> 自动依赖计算.使用 AutoReqProv: no 完全禁用所有这些东西.
  2. 但是,您可能需要构建一个与操作系统的其余部分更好地集成的程序包.例如,字体可能需要在适当的系统设施中注册,例如fontconfig.不幸的是,不同的 Linux rpm 发行版对此略有不同,嗯,习惯.实际上,您必须在现有字体包中检查该过程在您的发行版中的组织方式.您可以使用合适的源 rpm 包(检查 http://rpmfind.nethttp://rpm.pbone.net RPM 搜索引擎),提取其 .spec 文件并研究 %prein%postin%preun%postun 部分被组织起来.显然,字体包的名称中通常带有 -fonts- :)
  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 :)

毕竟,您可以使用 rpm --query --requires --package </path/to/file.rpm>rpm 显示卸载的 rpm 包的依赖项和提供--query --provides --package .已安装软件包的 deps 显示为 rpm --query --requires 等.

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.

这篇关于构建 RPM 以安装文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆