首页 文章

rpmbuild规范文件和rpm - 一些深刻的混淆

提问于
浏览
0

我正在尝试使用rpmbuild来执行以下操作 .

我有一个预建项目,在一个目录中大约有100个文件,作为tar文件 . 我想创建一个捆绑这些文件的RPM,当使用rpm -i安装在新机器上时,将解压缩文件,在/ usr / bin下创建一个目录,然后将它们复制到那里 . 最后,它应该运行一个bash脚本文件 .

运行rpmbuild -bs会创建一个SRPM,但是当我尝试使用rpm -i安装它时,没有任何反应 .

运行rpmbuild -bb运行所有步骤 - 配置,构建,安装等,其中大部分我不需要 . 但是,它不会创建RPM,并且安装步骤是我在目标机器上使用rpm -i时所期望的,而不是在我尝试创建RPM的机器上 .

我想我错过了一些基本的东西 . 任何提示?

1 回答

  • 2

    运行rpmbuild -bs会创建一个SRPM,但是当我尝试使用rpm -i安装它时,没有任何反应 .

    没什么 . 成功安装SRPM会将spec文件和源(包括补丁)安装到RPM构建树中,随时可以使用它构建RPM . 但是,根据您构建它的位置以及安装它的人,可能只是用相同的副本覆盖了原始源和规范 . SRPM不是您想要的,但您仍应创建一个以供将来使用 .

    运行rpmbuild -bb运行所有步骤 - 配置,构建,安装等,其中大部分我不需要 .

    当然可以,但是你必须采取任何措施 . 听起来你可以通过一个空的 %build scriptlet,以及一个空的 %prep scriptlet,如果你知道如何 . 大多数工作都可以在 %install 完成,这没关系 .

    但是,它不会创建RPM,

    这将是令人惊讶的 . 你确定你在正确的地方寻找吗?它将进入RPM构建区域中 RPMS/ 的相应特定于arch的子目录 . 例如, RPMS/x86_64/mypackage-1.2.3-1.x86_64.rpm .

    但当然,只有 rpmbuild 成功 . 由于各种原因,它可能在 %install 阶段后失败,但如果发生则会发出诊断 .

    当我使用rpm -i时,安装步骤是我期望在目标机器上发生的,而不是在我试图创建RPM的机器上 .

    那么,这在一定程度上取决于您如何在规范中编写安装scriptlet . 如果您正确地编写它,它将安装要打包的文件到 rpmbuild 指定给您的临时区域 .

    我想我错过了一些基本的东西 . 任何提示?

    我想你错过了几个基本的东西:

    • 构建RPM的规则#1: do not build RPMs as root! 您说安装步骤符合您的预期 rpm -i ,告诉我您违反了此规则 . 只有以root身份构建才能将 rpmbuild 文件写入系统目录 .

    • %install scriptlet(您在spec文件中提供)应该将文件写入以rpmbuild提供的构建根为根的文件系统映像,而不是以实际文件系统根为根的主树 . %install scriptlet可以通过 %{buildroot} 宏或 $BUILDROOT shell变量识别构建根目录 . scriptlet应该创建该目录及其所需的任何子目录,并编写要在那里安装的文件 .

    • 可以提供在程序包安装和/或删除时运行的脚本,这些很常见,但请确保在安装程序包文件后,您只能在目标系统上执行操作 . 例如,创建本地用户和配置系统服务 . 不要使用此类scriptlet执行您可能已经在程序包中烘焙的任何内容,例如设置文件所有权或权限或修改文件 .

    总的来说,听起来你想要这些东西:

    Name:           mypackage
    Version:        1.2.3
    Release:        1%{?dist}
    Summary:        My package
    
    License:        proprietary
    Source0:        mypackage-1.2.3.tar.gz
    
    # Only rather old rpmbuild requires you to choose a build root yourself
    # BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
    
    # You probably can let rpmbuild discover the dependencies for you
    # Requires:       
    
    %description
    My cool package.
    
    %prep
    # empty 
    
    %build
    # empty
    
    %install
    # make sure to start clean
    rm -rf %{buildroot}
    
    # Create the buildroot and appropriate directory structure within
    mkdir -p %{buildroot}%{_bindir}
    cd %{buildroot}%{_bindir}
    
    # Unpack the tarball directly into the build root.
    # This is a bit unusual, but it works when your tarball contains pre-built
    # binaries.  The macro %{S:0} refers to source 0.
    tar -xzf %{S:0}
    
    # Optionally move / rename the unpacked directory or its contents    
    mv mypackage-1.2.3 mypackage
    
    %files
    # Installed files will be owned by root:root, but they will have whatever
    # modes they do in the build root:
    %defattr(-,root,root,-)
    
    # Or whatever the install directory was, less the build root portion:
    %{_bindir}/mypackage
    
    %post
    # post-installation script inline here ...
    # Can use the installed files, including running scripts among them.
    # Make sure that this script cannot exit with a nonzero exit status.
    
    %changelog
    * Fri Jun 08 2018 user3587642 <user3587642@mail.com> 1.2.3-1
    - Initial spec
    

相关问题