How do I extract the contents of an rpm?

前端 未结 14 1887

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

相关标签:
14条回答
  • 2020-12-12 10:23

    Copy the .rpm file in a separate folder then run the following command $ yourfile.rpm | cpio -idmv

    0 讨论(0)
  • 2020-12-12 10:28

    You can simply do tar -xvf <rpm file> as well!

    0 讨论(0)
  • 2020-12-12 10:33

    Most distributions have installed the GUI app file-roller which unpacks tar, zip, rpm and many more.

    file-roller --extract-here package.rpm
    

    This will extract the contents in the current directory.

    0 讨论(0)
  • 2020-12-12 10:36

    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.

    0 讨论(0)
  • 2020-12-12 10:38

    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:

    COMPRESSION='/dev/stdin: XZ compressed data'
    

    Simply replacing 'grep -q' with 'grep -q -i' everywhere seems to resolve the issue well.

    I've done a few updates, particularly adding some comments and using "case" instead of stacked "if" statements, and included that fix below

    #!/bin/sh
    #
    # rpm2cpio.sh - extract 'cpio' contents of RPM
    #
    # Typical usage: rpm2cpio.sh rpmname | cpio -idmv
    #
    
    if [ "$# -ne 1" ]; then
        echo "Usage: $0 file.rpm" 1>&2
        exit 1
    fi
    
    rpm="$1"
    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 \* $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 $rpm`
    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=$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
    
    0 讨论(0)
  • 2020-12-12 10:39

    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 
    
    0 讨论(0)
提交回复
热议问题