Linux 如何提取 rpm 的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18787375/
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 do I extract the contents of an rpm?
提问by Jeff Sheffield
I have an rpm and I want to treat it like a tarball. I want to extract the contents into a directory so I can inspect the contents. I am familiar with the querying commands of an uninstalled package. I do not simply want a list of the contents of the rpm. i.e.
我有一个 rpm,我想把它当作一个 tarball。我想将内容提取到一个目录中,以便我可以检查内容。我熟悉卸载包的查询命令。我不只是想要一个 rpm 的内容列表。IE
$ rpm -qpl foo.rpm
I want to inspect the contents of several files contained in the rpm. I do not want to install the rpm.I am also aware of the rpms ability to do additional modifictions in the %post sections, and how to check for those. i.e.
我想检查 rpm 中包含的几个文件的内容。我不想安装rpm。我也知道 rpms 能够在 %post 部分进行额外的修改,以及如何检查这些。IE
$ rpm -qp --scripts foo.rpm
However in this case that is of no concern to me.
但是,在这种情况下,这与我无关。
采纳答案by linux_fanatic
Did you try the rpm2cpio
commmand? See the example below:
你试过命令rpm2cpio
吗?请参阅下面的示例:
$ rpm2cpio php-5.1.4-1.esp1.x86_64.rpm | cpio -idmv
/etc/httpd/conf.d/php.conf
./etc/php.d
./etc/php.ini
./usr/bin/php
./usr/bin/php-cgi
etc
回答by Jeff Sheffield
$ mkdir packagecontents; cd packagecontents
$ rpm2cpio ../foo.rpm | cpio -idmv
$ find .
For Reference: the cpio arguments are
供参考: cpio 参数是
-i = extract
-d = make directories
-m = preserve modification time
-v = verbose
I found the answer over here: lontar's answer
我在这里找到了答案:lontar's answer
回答by rook
Sometimes you can encounter an issue with intermediate RPM archive:
有时您会遇到中间 RPM 存档的问题:
cpio: Malformed number
cpio: Malformed number
cpio: Malformed number
. . .
cpio: premature end of archive
cpio:格式错误的数字
cpio:格式错误的数字
cpio:格式错误的数字
。. .
cpio:存档过早结束
That means it could be packed, these days it is LZMA2 compression as usual, by xz
:
这意味着它可以被打包,现在它像往常一样是 LZMA2 压缩,通过xz
:
rpm2cpio <file>.rpm | xz -d | cpio -idmv
otherwise you could try:
否则你可以尝试:
rpm2cpio <file>.rpm | lzma -d | cpio -idmv
回答by Jeff Johnson
For those who do not have rpm2cpio, here is the ancient rpm2cpio.sh script that extracts the payload from a *.rpm package.
对于那些没有 rpm2cpio 的人,这里是古老的 rpm2cpio.sh 脚本,它从 *.rpm 包中提取有效负载。
Reposted for posterity … and the next generation.
为后代转发……以及下一代。
Invoke like this: ./rpm2cpio.sh .rpm | cpio -dimv
像这样调用: ./rpm2cpio.sh .rpm | cpio -dimv
#!/bin/sh
pkg=
if [ "$pkg" = "" -o ! -e "$pkg" ]; then
echo "no package supplied" 1>&2
exit 1
fi
leadsize=96
o=`expr $leadsize + 8`
set `od -j $o -N 8 -t u1 $pkg`
il=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
dl=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
# echo "sig il: $il dl: $dl"
sigsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $sigsize + \( 8 - \( $sigsize \% 8 \) \) \% 8 + 8`
set `od -j $o -N 8 -t u1 $pkg`
il=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
dl=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
# echo "hdr il: $il dl: $dl"
hdrsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $hdrsize`
EXTRACTOR="dd if=$pkg ibs=$o skip=1"
COMPRESSION=`($EXTRACTOR |file -) 2>/dev/null`
if echo $COMPRESSION |grep -q gzip; then
DECOMPRESSOR=gunzip
elif echo $COMPRESSION |grep -q bzip2; then
DECOMPRESSOR=bunzip2
elif echo $COMPRESSION |grep -iq xz; then # xz and XZ safe
DECOMPRESSOR=unxz
elif echo $COMPRESSION |grep -q cpio; then
DECOMPRESSOR=cat
else
# Most versions of file don't support LZMA, therefore we assume
# anything not detected is LZMA
DECOMPRESSOR=`which unlzma 2>/dev/null`
case "$DECOMPRESSOR" in
/* ) ;;
* ) DECOMPRESSOR=`which lzmash 2>/dev/null`
case "$DECOMPRESSOR" in
/* ) DECOMPRESSOR="lzmash -d -c" ;;
* ) DECOMPRESSOR=cat ;;
esac
;;
esac
fi
$EXTRACTOR 2>/dev/null | $DECOMPRESSOR
回答by Nico Kadel-Garcia
The "DECOMPRESSION" test fails on CygWin, one of the most potentiaally useful platforms for it, due to the "grep" check for "xz" being case sensitive. The result of the "COMPRESSION:" check is:
由于对“xz”的“grep”检查区分大小写,因此“DECOMPRESSION”测试在 CygWin 上失败,CygWin 是对其最有用的平台之一。“压缩:”检查的结果是:
COMPRESSION='/dev/stdin: XZ compressed data'
Simply replacing 'grep -q' with 'grep -q -i' everywhere seems to resolve the issue well.
简单地将 'grep -q' 替换为 'grep -q -i' 似乎可以很好地解决问题。
I've done a few updates, particularly adding some comments and using "case" instead of stacked "if" statements, and included that fix below
我做了一些更新,特别是添加了一些评论并使用“case”而不是堆叠的“if”语句,并在下面包含了该修复
#!/bin/sh
#
# rpm2cpio.sh - extract 'cpio' contents of RPM
#
# Typical usage: rpm2cpio.sh rpmname | cpio -idmv
#
if [ "$# -ne 1" ]; then
echo "Usage: java -cp redline-1.2.1-jar-with-dependencies.jar org.redline_rpm.Scanner foo.rpm
file.rpm" 1>&2
exit 1
fi
rpm=""
if [ -e "$rpm" ]; then
echo "Error: missing $rpm"
fi
leadsize=96
o=`expr $leadsize + 8`
set `od -j $o -N 8 -t u1 $rpm`
il=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
dl=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
# echo "sig il: $il dl: $dl"
sigsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $sigsize + \( 8 - \( $sigsize \% 8 \) \) \% 8 + 8`
set `od -j $o -N 8 -t u1 $rpm`
il=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
dl=`expr 256 \* \( 256 \* \( 256 \* + \) + \) + `
# echo "hdr il: $il dl: $dl"
hdrsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $hdrsize`
EXTRACTOR="dd if=$rpm ibs=$o skip=1"
COMPRESSION=`($EXTRACTOR |file -) 2>/dev/null`
DECOMPRESSOR="cat"
case $COMPRESSION in
*gzip*|*GZIP*)
DECOMPRESSOR=gunzip
;;
*bzip2*|*BZIP2*)
DECOMPRESSOR=bunzip2
;;
*xz*|*XZ*)
DECOMPRESSOR=unxz
;;
*cpio*|*cpio*)
;;
*)
# Most versions of file don't support LZMA, therefore we assume
# anything not detected is LZMA
DECOMPRESSOR="`which unlzma 2>/dev/null`"
case "$DECOMPRESSOR" in
/*)
DECOMPRESSOR="$DECOMPRESSOR"
;;
*)
DECOMPRESSOR=`which lzmash 2>/dev/null`
case "$DECOMPRESSOR" in
/* )
DECOMPRESSOR="lzmash -d -c"
;;
* )
echo "Warning: DECOMPRESSOR not found, assuming 'cat'" 1>&2
;;
esac
;;
esac
esac
$EXTRACTOR 2>/dev/null | $DECOMPRESSOR
回答by Melissa
You can simply do tar -xvf <rpm file>
as well!
你也可以简单地做tar -xvf <rpm file>
!
回答by Ronan Quillevere
To debug / inspect your rpm I suggest to use redlinewhich is a java program
要调试/检查您的 rpm,我建议使用redline,它是一个 Java 程序
Usage :
用法 :
unrpm file.rpm
回答by user2394284
In OpenSuse at least, the unrpm
command comes with the build
package.
至少在 OpenSuse 中,该unrpm
命令随build
包一起提供。
In a suitable directory (because this is an archive bomb):
在合适的目录中(因为这是一个存档炸弹):
file-roller --extract-here package.rpm
回答by erik
Most distributions have installed the GUI app file-rollerwhich unpacks tar, zip, rpm and many more.
大多数发行版都安装了 GUI 应用文件滚轮,它可以解压tar、zip、rpm 等等。
##代码##This will extract the contents in the current directory.
这将提取当前目录中的内容。
回答by Davide Cesari
The powerful text-based file manager mc(Midnight Commander, vaguely reminding the Norton Commander of old DOS times) has the built-in capability of inspecting and unpacking .rpm and .rpms files, just "open" the .rpm(s) file within mc and select CONTENTS.cpio
: for an rpm you get access to the install tree, for an rpms you get access to the .spec file and all the source packages.
强大的基于文本的文件管理器mc(Midnight Commander,模糊地提醒了旧 DOS 时代的 Norton Commander)具有检查和解包 .rpm 和 .rpms 文件的内置功能,只需“打开”.rpm(s) 文件在 mc 中并选择CONTENTS.cpio
:对于 rpm,您可以访问安装树,对于 rpm,您可以访问 .spec 文件和所有源包。