How do I extract the contents of an rpm? How do I extract the contents of an rpm? linux linux

How do I extract the contents of an rpm?


Did you try the rpm2cpio commmand? See the example below:

$ 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 


$ 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


For those who do not have rpm2cpio, here is the ancient rpm2cpio.sh scriptthat extracts the payload from a *.rpm package.

Reposted for posterity … and the next generation.

Invoke like this: ./rpm2cpio.sh .rpm | cpio -dimv

#!/bin/shpkg=$1if [ "$pkg" = "" -o ! -e "$pkg" ]; then    echo "no package supplied" 1>&2    exit 1fileadsize=96o=`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=gunzipelif echo $COMPRESSION |grep -q bzip2; then        DECOMPRESSOR=bunzip2elif echo $COMPRESSION |grep -iq xz; then # xz and XZ safe        DECOMPRESSOR=unxzelif echo $COMPRESSION |grep -q cpio; then        DECOMPRESSOR=catelse        # 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                 ;;        esacfi$EXTRACTOR 2>/dev/null | $DECOMPRESSOR