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
To debug / inspect your rpm I suggest to use redline which is a java program
Usage :
java -cp redline-1.2.1-jar-with-dependencies.jar org.redline_rpm.Scanner foo.rpm
Download : https://github.com/craigwblake/redline/releases
In NixOS, there is rpmextract
. It is a wrapper around rpm2cpio, exactly as @Alan Evangelista wanted.
https://github.com/NixOS/nixpkgs/tree/master/pkgs/tools/archivers/rpmextract
For those who do not have rpm2cpio, here is the ancient rpm2cpio.sh script that extracts the payload from a *.rpm package.
Reposted for posterity … and the next generation.
Invoke like this: ./rpm2cpio.sh .rpm | cpio -dimv
#!/bin/sh
pkg=$1
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 \* $2 + $3 \) + $4 \) + $5`
dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
# 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 \* $2 + $3 \) + $4 \) + $5`
dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
# 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
7-Zip is able to extract the contents. It works the same way that a tar.gz file works. A compressed file inside a compressed file.
On Windows 7 Pro with 7-Zip installed:
Right click the rpm file. Mouse over 7-Zip in the context menu. Select extract to "filename".
Enter into the filename folder.
Right click the cpio file. Mouse over 7-Zip in the context menu. Select extract to "filename".
You are done. The folder with "filename" contains the extracted contents for inspecting.
I know you Linux guys despise things being made easy, but in the long run, if you have to spend time hunting down a solution to a simple problem like this; that inefficiency is costing you money.
Given the fact that you Linux guys despise efficient simplicity, I highly doubt that the Linux version of 7-Zip will do the same thing in the exact same way.
Why make it easy when you can make downright stupid hard and claim to be a genius at the same time?
Just to be clear; I'm not a Windows fanboy. I'm actually looking into moving over to Linux. I just couldn't resist the opportunity to rub what Windows developers would see as common sense, best developer practices into your faces.
Just be glad it's me posting this and you don't have Mark Harmon standing next to you cause; Special agent Leroy Jethro Gibbs would have done given you a head slap for not using your head.
I don't know which Gibbs rule it is but the rule is: Don't make things harder for yourself than they have to be.
Now we get to see who needs to take a vacation. Take care!
$ mkdir packagecontents; cd packagecontents
$ rpm2cpio ../foo.rpm | cpio -idmv
$ find .
For Reference: the cpio arguments are
-i = extract
-d = make directories
-m = preserve modification time
-v = verbose
I found the answer over here: lontar's answer
Sometimes you can encounter an issue with intermediate RPM archive:
cpio: Malformed number
cpio: Malformed number
cpio: Malformed number
. . .
cpio: premature end of archive
That means it could be packed, these days it is LZMA2 compression as usual, by xz
:
rpm2cpio <file>.rpm | xz -d | cpio -idmv
otherwise you could try:
rpm2cpio <file>.rpm | lzma -d | cpio -idmv