rpm.spec 文件中的多个 tar(源文件)文件

multiple tar (source files) files in rpm.spec file

我在 linux 上想出了一个集中式日志服务器。在这一点上,我正在尝试整合以使事情更容易加载到另一台机器上。我想要一个可以一次性安装多个程序的 RPM。我正在 CentOS 7 服务器上工作。我希望打包到 rpm 中的程序是:

eventlog 2.12 
libdbi 0.9.0
freetds 0.91 
libdbi-drivers 0.9.0
json-c
syslog-ng 3.5.6

我已经对 RPM 做了很多阅读,只是很难理解如何将多个源放入一个 RPM。我是源安装这些而不只是 yum 安装它们的原因是因为我需要在“./configure --enable-example”中调用的配置。所以我在我的机器上安装了所有这些程序,然后我 tar 备份它们并尝试使用该文件作为源。任何能为我指明正确方向的想法或任何人都将不胜感激。

您可以根据需要列出任意多的 Source 行,并在您的规范文件中有任意多的 %setup 宏调用,只要您需要匹配。

从在线最大 RPM 一书中的 Using %setup in a Multi-source Spec File 部分我们发现:

For the purposes of this example, our spec file will have the following three source tags: [1]

 source: source-zero.tar.gz
 source1: source-one.tar.gz
 source2: source-two.tar.gz

To unpack the first source is not hard; all that's required is to use %setup with no options:

%setup

This produces the following set of commands:

cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
  exit $?
fi
cd cdplayer-1.0
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .

....

Now let's add the second source file. Things get a bit more interesting here. First, we need to identify which source tag (and therefore, which source file) we're talking about. So we need to use either the -a or -b option, depending on the characteristics of the source archive. For this example, let's say that -a is the option we want. Adding that option, plus a "1" to point to the source file specified in the source1 tag, we have:

%setup -a 1

Since we've already seen that using the -a or -b option results in duplicate unpacking, we need to disable the default unpacking by adding the -T option:

%setup -T -a 1

Next, we need to make sure that the top-level directory isn't deleted. Otherwise, the first source file we just unpacked would be gone. That means we need to include the -D option to prevent that from happening. Adding this final option, and including the now complete macro in our %prep script, we now have:

%setup
%setup -T -D -a 1

This will result in the following commands:

cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
  exit $?
fi
cd cdplayer-1.0
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .
cd /usr/src/redhat/BUILD
cd cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-one.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
  exit $?
fi
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .

So far, so good. Let's include the last source file, but with this one, we'll say that it needs to be unpacked in a subdirectory of cdplayer-1.0 called database. Can we use %setup in this case?

We could, if source-two.tgz created the database subdirectory. If not, then it'll be necessary to do it by hand. For the purposes of our example, let's say that source-two.tgz wasn't created to include the database subdirectory, so we'll have to do it ourselves. Here's our %prep script now:

%setup
%setup -T -D -a 1
mkdir database
cd database
gzip -dc /usr/src/redhat/SOURCES/source-two.tar.gz | tar -xvvf -

Here's the resulting script:

cd /usr/src/redhat/BUILD
rm -rf cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-zero.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
  exit $?
fi
cd cdplayer-1.0
cd /usr/src/redhat/BUILD/cdplayer-1.0
chown -R root.root .
chmod -R a+rX,g-w,o-w .
cd /usr/src/redhat/BUILD
cd cdplayer-1.0
gzip -dc /usr/src/redhat/SOURCES/source-one.tar.gz | tar -xvvf -
if [ $? -ne 0 ]; then
  exit $?
fi
mkdir database
cd database
gzip -dc /usr/src/redhat/SOURCES/source-two.tar.gz | tar -xvvf -

The three commands we added to unpack the last set of sources were added to the end of the %prep script.

在这种情况下,正确的解决方案是创建多个 RPM,并在它们各自的 .spec 文件的 Requires: 字段中简单地声明它们之间依赖关系的正确顺序。

正确定义关系后,rpm(8) 或 yum(8) 将以正确的顺序安装它们。

这种方法也促进了模块化。