安装 RPM 不会 运行 .spec 中列出的所有 %install 操作

Installing RPM doesn't run all the %install actions listed in .spec

TL;DR:我制作了一个成功构建 .rpm 的 .spec 文件,但 rpm -i <file>.rpm 没有执行我认为应该执行的所有操作。为什么?

摘自<file>.spec

%install
sudo python2.7 -m pip install 'tornado<5'
...#other pip commands...
cp -r $RPM_BUILD_DIR/%{name}-%{version}/* %{buildroot}

(我知道这不是理想的做法,但我被迫使用CentOS 6并且无法升级python的系统版本因为corporate/shared环境所以这是我能想到的最好方法。)

在构建 .rpm%install 下的所有命令都是正确的 运行,因此所有 pip 包都安装在创建 [=12] 的机器上=] 来自 .specrpmbuild -ba <file>.specexit 0 结束。但是,当我尝试安装创建的 .noarch.rpm 文件时(在另一个具有相同 OS/architecture 的系统上),所发生的只是安装了 rpm 指定的依赖项并将文件推送到正确的目录,但来自 %install 的其他命令不是 运行。最终发生的事情是,我尝试调用生成的可执行文件,但由于缺少 python 包而出错。

RPM.org says:

Performing any tasks required before the install:

There are cases where one or more commands must be given prior to the actual installation of a package. RPM performs these commands exactly as directed by the package builder, thus eliminating a common source of problems during installations.

...如果不在 .spec 文件的 %install 字段中,我应该在安装包之前在哪里指定命令 运行?

%install scriptlet 运行 在构建期间,而不是在安装期间。

如果您希望在安装包时命令是 运行,那么您需要使用 spec 文件中的 %post 部分。

如果你想在安装 rpm 后执行 运行 命令,你需要将这些命令放在 %post 目标中。

如果您希望命令在安装 rpm 本身之前 运行,请将命令放在 %pre 目标中。

%install中的命令在您构建.rpm时执行,而不是运行在您安装.rpm时执行。

%install 旨在将您的软件安装到沙盒目录层次结构中,然后将其打包并包含到 .rpm 文件中。

不要在 %install 中使用 运行 命令改变任何系统状态或影响 $RPM_BUILD_DIR 或 %{buildroot}

之外的任何东西

正如其他人指出的那样,%install 是规范文件中的脚本部分,用于 复制 %build 阶段已经编译的文件(其中可以是 python 的空操作)。但是,其他人还没有注意到 sudo python2.7 -m pip install 'tornado<5' 绝对 不是 您应该在规范文件中使用的命令。您需要通过其他方式获取 python 文件并将它们安装到 %{buildroot}.

下的正确位置

RPM 应该永远不会 作为 root 用户构建,也不会调用 sudo 任何地方。曾经。