差异两个rpms? - linux

时间:2015-12-14 19:48:19

标签: linux diff rpm

对我的基线(java / C ++)进行了一些未知的更改并安装在新的rpm中。我想要一种方法来比较此rpm的内容与旧的内容,以查看所做的更改。这可能吗?

如果没有简单的方法,有没有办法获得按日期组织的rpm文件名的内容列表?

3 个答案:

答案 0 :(得分:9)

尝试使用pkgdiff来查看RPM包之间的差异:

pkgdiff PKG-0.rpm PKG-1.rpm

如果您比较SRC.RPM,那么该工具也将提取并比较内部tarball(除非定义了 -skip-subarchives 选项)。

enter image description here

enter image description here

答案 1 :(得分:2)

如果您有以前的rpm包文件,可以将其解压缩,例如,使用unrpm进入临时目录,并使用diff -r比较结果。

以下是我在ncurses的两个开发版本之间进行说明的示例:

#!/bin/sh

failed() {
    echo "? $*" >&2
    exit 1
}

# get the package filename as parameter, defaulting to one used for example
oldpkg=$(readlink -f "${1:-/tmp/ncurses6-6.0-20150926.x86_64.rpm}")
pkgname=$(rpm -qip "$oldpkg" 2>/dev/null | awk '/^Name .*:/ { print $3; exit 0; }')

[ -f "$oldpkg" ] || failed "no package file found: $oldpkg"
[ -n "$pkgname" ] || failed "no package name found in $oldpkg"

# The tags for this question are "linux" and "rpm", so mktemp and bash are assumed.
tempdir=$(mktemp -d "${TMPDIR:-/tmp}/pkgcompare.XXXXXX")
trap 'rm -rf "$tempdir"' EXIT ERR

# Fedora sets CDPATH, which would echo (cancel that).
unset CDPATH

mkdir -p "$tempdir"/{new-version,old-version}

cd "$tempdir/new-version" || exit
# the query returns absolute pathnames beginning with "/"
rpm -ql "$pkgname" | while :
do
    read path
    [ -z "$path" ] && break
    [ -d "$path" ] && mkdir -p ".$path"
    [ -f "$path" ] && mkdir -p "./${path%/*}"
    [ -f "$path" ] && cp -p "$path" ".$path"
done

cd "$tempdir/old-version" || exit
rpm2cpio "$oldpkg" | cpio -i -d 2>/dev/null

cd $tempdir || exit
# I would usually pipe this into diffstat, but you may want the actual diffs
diff -r -u -N old-version new-version | diffstat

和输出(仅剩diffstat,其他输出被抑制):

 bin/ncursesw6-config           |    2 +-
 include/ncursesw6/curses.h     |    8 ++++----
 include/ncursesw6/ncurses.h    |    8 ++++----
 lib64/libncurses++w6.so        |binary
 lib64/libncurses++w6.so.6      |binary
 lib64/libncurses++w6.so.6.0    |binary
 lib64/libncursesw6.so          |binary
 lib64/libncursesw6.so.6        |binary
 lib64/libncursesw6.so.6.0      |binary
 lib64/libtinfow6.so            |binary
 lib64/libtinfow6.so.6          |binary
 lib64/libtinfow6.so.6.0        |binary
 lib64/pkgconfig/formw6.pc      |    2 +-
 lib64/pkgconfig/menuw6.pc      |    2 +-
 lib64/pkgconfig/ncurses++w6.pc |    2 +-
 lib64/pkgconfig/ncursesw6.pc   |    2 +-
 lib64/pkgconfig/panelw6.pc     |    2 +-
 lib64/pkgconfig/ticw6.pc       |    2 +-
 lib64/pkgconfig/tinfow6.pc     |    2 +-
 19 files changed, 16 insertions(+), 16 deletions(-)

你当然可以对两个rpm包应用相同的方法;这个问题显然已经安装了一个,另一个可以访问。

答案 2 :(得分:-1)

要严格比较两个rpm文件(我们将它们称为 one.rpm another.rpm ),您还需要检查digests of the constituent files请检查pre- and post-[un]install scripts(因为这些脚本可能会修改系统状态):

$ diff <(rpm -q --dump --scripts -p one.rpm) <(rpm -q --dump --scripts -p another.rpm)

您可能还想比较signatories(如果有):

$ diff <(rpm -q --qf '%{SIGPGP:pgpsig}\n%{SIGPGP:armor}\n' -p one.rpm) <(rpm -q --qf '%{SIGPGP:pgpsig}\n%{SIGPGP:armor}\n' -p another.rpm)

(或if you're especially pedantic

$ diff <(rpm -q --qf '%{DSAHEADER:pgpsig}\n%{DSAHEADER:armor}\n%{RSAHEADER:pgpsig}\n%{DSAHEADER:armor}\n%{SIGGPG:pgpsig}\n%{SIGGPG:armor}\n%{SIGPGP:pgpsig}\n%{SIGPGP:armor}\n' -p one.rpm) <(rpm -q --qf '%{DSAHEADER:pgpsig}\n%{DSAHEADER:armor}\n%{RSAHEADER:pgpsig}\n%{DSAHEADER:armor}\n%{SIGGPG:pgpsig}\n%{SIGGPG:armor}\n%{SIGPGP:pgpsig}\n%{SIGPGP:armor}\n' -p another.rpm)