repoquery --whatrequires - 安装<package>和yum remove <package>输出是不同的。如何获得相同的依赖项输出?

时间:2016-05-27 15:15:30

标签: centos redhat

如何在删除yum之前检查将删除哪些依赖项?我刚刚发现两个包之间存在一些差异,所以请求你的帮助。

JDK示例(在执行yum时没有依赖关系,但repoquery显示依赖关系 - 为什么存在差异?)

    root@server DEV # yum remove jdk-1.7.0_101-fcs.x86_64
. . .
    Dependencies Resolved

    =================================================================================================================================================
     Package               Arch                     Version                                Repository                                           Size
    =================================================================================================================================================
    Removing:
     jdk                   x86_64                   2000:1.7.0_101-fcs                     @rhel6-x86_64-660-barclays-custom                   209 M

    Transaction Summary
    =================================================================================================================================================
    Remove        1 Package(s)

    Installed size: 209 M
    Is this ok [y/N]: ^CExiting on user Command

    root@server DEV # repoquery --whatrequires --installed jdk-1.7.0_101-fcs.x86_64
    jdk-2000:1.7.0_101-fcs.x86_64
    axis-0:1.2.1-7.5.el6_5.noarch
    log4j-0:1.2.14-6.4.el6.x86_64
    mx4j-1:3.0.1-9.13.el6.noarch
    wsdl4j-0:1.5.2-7.8.el6.noarch
    xml-commons-resolver-0:1.1-4.18.el6.x86_64
    root@server DEV #

java gcj在这种情况下工作正常:

    root@server DEV # repoquery --whatrequires --installed java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
    java-1.5.0-gcj-0:1.5.0.0-29.1.el6.x86_64
    axis-0:1.2.1-7.5.el6_5.noarch
    bcel-0:5.2-7.2.el6.x86_64
    classpathx-jaf-0:1.0-15.4.el6.x86_64
    classpathx-mail-0:1.1.1-9.4.el6.noarch
    ecj-1:3.4.2-6.el6.x86_64
    jakarta-commons-daemon-1:1.0.1-8.9.el6.x86_64
    jakarta-commons-httpclient-1:3.1-0.9.el6_5.x86_64
    jakarta-commons-pool-0:1.3-12.7.el6.x86_64
    java-1.5.0-gcj-0:1.5.0.0-29.1.el6.x86_64
    java_cup-1:0.10k-5.el6.x86_64
    log4j-0:1.2.14-6.4.el6.x86_64
    mx4j-1:3.0.1-9.13.el6.noarch
    regexp-0:1.5-4.4.el6.x86_64
    sinjdoc-0:0.5-9.1.el6.x86_64
    tomcat6-0:6.0.24-80.el6.x86_64
    wsdl4j-0:1.5.2-7.8.el6.noarch
    xml-commons-apis-0:1.3.04-3.6.el6.x86_64
    xml-commons-resolver-0:1.1-4.18.el6.x86_64

    root@server DEV # yum remove java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
. . .
    Dependencies Resolved

    =================================================================================================================================================
     Package                                     Arch                    Version                            Repository                          Size
    =================================================================================================================================================
    Removing:
     java-1.5.0-gcj                              x86_64                  1.5.0.0-29.1.el6                   @rhel6-x86_64-660                  150 k
    Removing for dependencies:
     axis                                        noarch                  1.2.1-7.5.el6_5                    @rhel6-x86_64-660                  1.6 M
     bcel                                        x86_64                  5.2-7.2.el6                        @rhel6-x86_64-660                   16 M
     classpathx-jaf                              x86_64                  1.0-15.4.el6                       @rhel6-x86_64-660                  240 k
     classpathx-mail                             noarch                  1.1.1-9.4.el6                      @rhel6-x86_64-660                  822 k
     ecj                                         x86_64                  1:3.4.2-6.el6                      @rhel6-x86_64-660                  7.3 M
     jakarta-commons-daemon                      x86_64                  1:1.0.1-8.9.el6                    @rhel6-x86_64-660                  121 k
     jakarta-commons-dbcp                        noarch                  1.2.1-13.8.el6                     @rhel6-x86_64-660                  125 k
     jakarta-commons-httpclient                  x86_64                  1:3.1-0.9.el6_5                    @rhel6-x86_64-660                  1.8 M
     jakarta-commons-pool                        x86_64                  1.3-12.7.el6                       @rhel6-x86_64-660                  368 k
     java_cup                                    x86_64                  1:0.10k-5.el6                      @rhel6-x86_64-660                  544 k
     log4j                                       x86_64                  1.2.14-6.4.el6                     @rhel6-x86_64-660                  2.0 M
     mx4j                                        noarch                  1:3.0.1-9.13.el6                   @rhel6-x86_64-660                  1.7 M
     regexp                                      x86_64                  1.5-4.4.el6                        @rhel6-x86_64-660                  248 k
     sinjdoc                                     x86_64                  0.5-9.1.el6                        @rhel6-x86_64-660                  2.3 M
     tomcat6                                     x86_64                  6.0.24-80.el6                      @rhel6-x86_64-660                  189 k
     tomcat6-lib                                 x86_64                  6.0.24-80.el6                      @rhel6-x86_64-660                  3.2 M
     wsdl4j                                      noarch                  1.5.2-7.8.el6                      @rhel6-x86_64-660                  339 k
     xml-commons-apis                            x86_64                  1.3.04-3.6.el6                     @rhel6-x86_64-660                  1.6 M
     xml-commons-resolver                        x86_64                  1.1-4.18.el6                       @rhel6-x86_64-660                  416 k

    Transaction Summary
    =================================================================================================================================================
    Remove       20 Package(s)

    Installed size: 41 M
    Is this ok [y/N]: ^CExiting on user Command
    root@serverDEV #

我甚至试过repoquery --whatrequires --installed --exactdeps <package>。这不会显示java gcj的依赖关系,这是不正确的。

1 个答案:

答案 0 :(得分:1)

我发现解决方案列出与yum remove完全相同的依赖关系列表,然后删除。

因此,您可以采取适当的预删除操作,并了解将要删除的内容。

作为首发,我已经用bash编写了这个,但这可以很容易地转换为Puppet脚本,Chef配方或任何自动化工具。主命令是sudo -u nobody rpm -e --test,它有两个保护门,以确保这是一个只读命令。

打印完整依赖关系列表的脚本:

#!/bin/bash

LEVEL="$1"
LEVEL=`rpm -q $LEVEL`

if [ "$?" == "0" ]
then
  ALL=$LEVEL

  time while :
  do
    OLD_DEP_COUNT=`echo $ALL| wc -w`
    LEVEL=`sudo -u nobody rpm -e --test $LEVEL 2>&1 | grep -v 'Failed dependencies' | awk -F " " '{print $NF}' | sed -e s/[0-9]://g`
    ALL="`echo "$LEVEL $ALL" | xargs -n1 | sort -u | xargs`"
    NEW_DEP_COUNT=`echo $ALL | wc -w`
    if [ "$OLD_DEP_COUNT" == "$NEW_DEP_COUNT" ]
    then
      for i in $ALL; do echo $i; done
      echo "The count of dependencies:"
      echo $ALL | wc -w
      break
    fi
  done
else
  echo "Cannot find the package"
fi

用法:

./script package_name