我正在尝试使用 rpmbuild 来执行以下操作。
我有一个预构建的项目,单个目录中有大约 100 个文件,作为 tar 文件。我想创建一个 RPM 来捆绑这些文件,当使用 rpm -i 安装在新机器上时,将解压这些文件,在/usr/bin 下创建一个目录,并将它们复制到那里。最后,它应该运行 bash 脚本文件。
运行 rpmbuild -bs 创建一个 SRPM,但是当我尝试使用 rpm -i 安装它时,没有任何反应。
运行 rpmbuild -bb 会运行所有步骤 - 配置、构建、安装等,其中大部分我不需要。但是,它不会创建 RPM,并且安装步骤是我使用 rpm -i 时预期在目标计算机上发生的情况,而不是在我尝试创建 RPM 的计算机上发生的情况。
我想我错过了一些基本的东西。有什么提示吗?
最佳答案
Running rpmbuild -bs creates an SRPM, but when I try to install that with rpm -i, nothing happens.
不是什么都没有。成功安装 SRPM 会将规范文件和源代码(包括补丁)安装到您的 RPM 构建树中,为您构建 RPM 做好准备。然而,根据您构建它的位置以及安装它的人,这可能只是用相同的副本覆盖了您的原始源和规范。 SRPM 不是您想要的,但您仍然应该创建一个供您自己将来使用。
Running rpmbuild -bb runs all the steps - configure, build, install, etc, most of which I don't need.
当然,但是您不需要的步骤不必做任何事情。听起来您可以使用空的 %build
scriptlet 和空的 %prep
scriptlet,如果您知道如何的话。大部分工作都可以在 %install
中完成,这很好。
However, it does not create an RPM,
这会令人惊讶。您确定您找对地方了吗?它将进入 RPM 构建区域中 RPMS/
的相应架构特定子目录。例如,RPMS/x86_64/mypackage-1.2.3-1.x86_64.rpm
。
当然,前提是 rpmbuild
成功。由于各种原因,它可能会在 %install
阶段之后失败,但如果失败,它会发出诊断信息。
and the install step is what I expected to happen on the target machine when I use rpm -i, not on the machine I'm trying to create the RPM on.
嗯,这部分取决于您如何在规范中编写安装脚本。如果您编写正确,那么它将安装要打包的文件到 rpmbuild
指定给您的暂存区域。
I think I'm missing something basic. Any hints?
我认为您缺少几个基本的东西:
构建 RPM 的规则 #1:不要以 root 身份构建 RPM! 你所说的安装步骤会按照你期望的
rpm -i
进行操作。我认为你违反了这条规则。只有当您以 root 身份构建时,rpmbuild
才有可能将文件写入系统目录。%install
scriptlet(您在规范文件中提供)应该将文件写入以 rpmbuild 提供的构建根为根的文件系统镜像,而不是以 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 <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87f2f4e2f5b4b2bfb0b1b3b5c7eae6eeeba9e4e8ea" rel="noreferrer noopener nofollow">[email protected]</a>> 1.2.3-1
- Initial spec
关于linux - rpmbuild 规范文件和 rpm - 一些深刻的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50753033/