搜索

此内容没有您所选择的语言版本。

2.10.4. Converting RPM Scripts

download PDF
This section describes general rules for converting RPM scripts that can often be found in the %prep, %build, %install, %check, %pre, and %post sections of a conventional spec file.
  • Replace all occurrences of %name with %pkg_name. Most importantly, this includes adjusting the %setup macro.
    • Adjust the %setup macro in the %prep section of the spec file so that the macro can deal with a different package name in the Software Collection environment:
      %setup -q -n %{pkg_name}-%{version}
      Note that the %setup macro is required and that you must always use the macro with the -n option to successfully build your Software Collection.
  • If you are using any of the %_root_ macros to point to the system file system hierarchy, you must use conditionals for these macros so that you can then use the spec file for building both the conventional package and the Software Collection. Edit the macros as in the following example:
    mkdir -p %{?scl:%_root_sysconfdir}%{?!scl:%_sysconfdir}
  • When building Software Collection packages that depend on other Software Collection packages, it is often important to ensure that the scl enable functionality links properly or run proper binaries, and so on. One of the examples where this is needed is compiling against a Software Collection library or running an interpreted script with the interpreter in the Software Collection.
    Wrap the script using the %{?scl: prefix, as in the following example:
    %{?scl:scl enable %scl - << \EOF}
     set -e
     ruby example.rb
     RUBYOPT="-Ilib" ruby bar.rb
     # The rest of the script contents goes here.
    %{?scl:EOF}
    It is important to specify set -e in the script so that the script behavior is consistent regardless of whether the script is executed in the rpm shell or the scl environment.
  • Pay attention to any scripts that are executed during the Software Collection package installation, such as:
    • %pretrans, %pre,
    • %post, %postun, %posttrans,
    • %triggerin, %triggerun, and %triggerpostun.
    If you use the scl enable functionality in those scripts, you are advised to start with an empty environment to avoid any unintentional collisions with the base system installation.
    To do so, use env -i - before enabling the Software Collection, as in the following example:
    %posttrans
    %{?scl:env -i - scl enable %{scl} - << \EOF}
    %vagrant_plugin_register %{vagrant_plugin_name}
    %{?scl:EOF}
  • All hardcoded paths found in RPM scripts must be replaced with proper macros. For example, replace all occurrences of /usr/share with %{_datadir}. This is needed because the $RPM_BUILD_ROOT variable and the %{build_root} macro are not relocated by the scl macro.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.