Linux 如何在不安装 RPM 的情况下“重新打包”RPM 文件,例如 cpio2rpm?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10580781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to "repackage" a RPM file for example cpio2rpm without installing the RPM?
提问by Dr Bob
- I'm able to extract files from a RPM file, but how do I "rebuild" it, for example cpio2rpm?
- I have extracted RPM file using following command. rpm2cpio theFileName.rpm | cpio –idmv
- I have to modify the few web application files like *.php, *.html or .js. These files don't require any source recompilation. So I would like to replaces or change these files with modification without rebuilding rpm. Since, I need to do this for multiple platforms like Redhat Linux and SUSE, and multiple architecture like 32 and 64 bit OS.
- I am expecting to do these changes on only on system and without rebuild rpm and there would not be have target system architecture dependency (like i386, 64).
- I am not looking like command rpmbuild –rebuild the.src.rpm since, I don't have source. I need to be rebuild binary .RPM file(not source .rpm)
I want to do this without source and platform or architecture independent and without using spec file if possible.
Any buddy, could you please suggest any solution or any free tools.
Thank you to all whoever spends time to read and reply to my thread.
- 我可以从 RPM 文件中提取文件,但是如何“重建”它,例如 cpio2rpm?
- 我使用以下命令提取了 RPM 文件。rpm2cpio theFileName.rpm | cpio –idmv
- 我必须修改少数 Web 应用程序文件,例如 *.php、*.html 或 .js。这些文件不需要任何源代码重新编译。所以我想通过修改替换或更改这些文件,而无需重建 rpm。因为,我需要为 Redhat Linux 和 SUSE 等多个平台以及 32 位和 64 位操作系统等多个架构执行此操作。
- 我希望仅在系统上进行这些更改,而无需重新构建 rpm,并且不会有目标系统架构依赖性(如 i386、64)。
- 我看起来不像命令 rpmbuild –rebuild the.src.rpm 因为我没有源代码。我需要重建二进制 .RPM 文件(不是源 .rpm)
我想在没有源和平台或架构独立的情况下这样做,如果可能的话,不使用规范文件。
任何朋友,您能否提出任何解决方案或任何免费工具。
感谢所有花时间阅读和回复我的帖子的人。
回答by glglgl
Principially you can pack everything you want into a RPM file. Just treat what you have as "source" and write a SPEC file which puts the data where the compiled binaries would normally go.
原则上,您可以将所需的所有内容打包到 RPM 文件中。只需将您拥有的内容视为“源”并编写一个 SPEC 文件,该文件将数据放在编译后的二进制文件通常会去的地方。
Concerning RPM, I consider "source" "what I have" and "binary" "what I need to run". Not very exact terminology, but it helps working with RPMs.
关于 RPM,我认为“源”“我拥有的”和“二进制”“我需要运行的”。不是很精确的术语,但它有助于使用 RPM。
Your spec file looks like any other spec file, what concerns the parameters etc. But the code part is different:
您的规范文件看起来像任何其他规范文件,涉及参数等。但代码部分不同:
[...]
%prep
# Here you either have nothing to do or you already unpack the cpio and possibly modify it.
# %build can be omitted
%install
[ "${buildroot}" != "/" ] && [ -d ${buildroot} ] && rm -rf ${buildroot};
# Here you can either unpack the cpio or copy the data unpacked in %prep.
# Be careful to put it into %{buildroot} or $RPM_BUILD_ROOT.
回答by JeremiahRo
You can repackage an installed RPM (including modified files) using rpmrebuild. http://rpmrebuild.sourceforge.net/
您可以使用 rpmrebuild 重新打包已安装的 RPM(包括修改后的文件)。http://rpmrebuild.sourceforge.net/
Obviously your binaries (if any) would have to be platform/architecture independent to work on all the OS flavors you're hoping for, but it sounds like if they're just web files that shouldn't be a problem.
显然,您的二进制文件(如果有)必须独立于平台/架构才能在您希望的所有操作系统风格上工作,但听起来它们只是网络文件,这应该不是问题。
回答by simon3270
You can use rpmrebuildto modify an actual rpm file (it doesn't need to be installed).
您可以使用rpmrebuild来修改实际的 rpm 文件(不需要安装)。
Most of the examples for this use complicated inline edit commands to modify known files in particular ways, but you can use a normal editor. I used this to fix a shell script in an rpm file that I didn't have the source for. Call the command as
大多数示例使用复杂的内联编辑命令以特定方式修改已知文件,但您可以使用普通编辑器。我用它来修复我没有源的 rpm 文件中的 shell 脚本。调用命令为
rpmrebuild -ep theFileName.rpm
This puts you in an editor with the spec file for the RPM. The name of the file will be something like ~/.tmp/rpmrebuild.12839/work/spec.2
. If you look in, in this example, ~/.tmp/rpmrebuild.12839/work
, you will find all of the files used to make the RPM (in my case, the file was in root/usr/sbin
within that directory). So, go to another window, cd to that directory, and edit any files you need to change.
这会将您置于带有 RPM 规范文件的编辑器中。该文件的名称将类似于~/.tmp/rpmrebuild.12839/work/spec.2
. 如果您查看本示例中的~/.tmp/rpmrebuild.12839/work
,您将找到用于制作 RPM 的所有文件(在我的例子中,该文件root/usr/sbin
位于该目录中)。因此,转到另一个窗口,cd 到该目录,然后编辑您需要更改的任何文件。
When you have finished editing files, go back to the edit window with the spec file, make any changes you need to that file (I didn't have any, since I wasn't adding or deleting files), save the file, and say "y" to the "Do you want to continue" question. It will then build a new RPM file, and tell you where it has put it (in my case, in ~/rpmbuild/RPMS/x86_64/)
完成文件编辑后,返回带有规范文件的编辑窗口,对该文件进行任何您需要的更改(我没有任何更改,因为我没有添加或删除文件),保存文件,然后对“您想继续吗”问题说“y”。然后它会构建一个新的 RPM 文件,并告诉你它把它放在哪里(在我的例子中,在 ~/rpmbuild/RPMS/x86_64/ 中)