【问题标题】:Listing packages that will be removed by "yum autoremove"?列出将被“yum autoremove”删除的包?
【发布时间】:2019-12-13 06:08:04
【问题描述】:
Running CentOS 7.6

我目前正在我的 kickstart 安装后脚本中卸载 Java yum remove java-1.7*。卸载 java 时,它会孤立 python-lxml 包,然后通过 yum autoremove -y 将其删除,因为它现在是叶子。

然后我使用 ansible 进行一堆配置,但在尝试使用“python-lxml”的任务中失败。

有没有办法列出“yum autoremove”将删除的所有包并将它们标记为不删除

【问题讨论】:

    标签: ansible centos rpm yum


    【解决方案1】:

    我最终查看了repoquery APIpackage-cleanup man page。使用package-cleanup,我能够通过传递--leaves-all 标志来列出系统上的所有叶子。然后,我将该输入通过管道传输到repoquery,以确定哪些叶子被标记为依赖项。 --qf 允许我指定查询格式。查看repoquery API,我可以看到我可以进行的各种 api 调用。

    querytags = [ 'name', 'version', 'release', 'epoch', 'arch', 'summary',
                  'description', 'packager', 'url', 'buildhost', 'sourcerpm',
                  'vendor', 'group', 'license', 'buildtime', 'filetime',
                  'installedsize', 'archivesize', 'packagesize', 'repoid', 
                  'requires', 'provides', 'conflicts', 'obsoletes',
                  'weak_requires', 'info_requires',
                  'weak_reverse_requires', 'info_reverse_requires', 
                  'relativepath', 'hdrstart', 'hdrend', 'id',
                  'checksum', 'pkgid', 'committer', 'committime',
                  'ui_evr', 'evr', 'ui_nevra', 'ui_envra',
                  'ui_from_repo', 'base_package_name', 'size', 'xattr_origin_url',
                  'ui_evra', 'ui_nevr', 'na', 'vr', 'vra', 'evr', 'evra',
                  'nvr', 'nvra', 'nevr', 'nevra', 'envr', 'envra',
    
                  'repo.<attr of the repo object>',
                  'yumdb.<attr of the yumdb object>',
                  '<attr of the yum object>'
                ]
    

    注意nvra (name-ver-rel.arch) 和yumdb.&lt;attr&gt; 标签,我可以查询yumdb 以获取传入的每个叶子的全名和reason

    然后我可以执行基本的grepsed 来提取我可以存储在数组中的包名称。

    package-cleanup --leaves -q --all | xargs repoquery --installed --qf '%\{nvra} - %\{yumdb_info.reason}' | grep -- '- dep' | sed "s/\s.*$//"
    

    使用这个数组,我能够逐步完成并将每个项目的reason 设置为user,因此yum autoremove -y 不会删除我打算在那里的内容。

    yumdb set reason user $array_item
    

    或者如果你想要所有 bash one 班轮的母亲......

    array=$(package-cleanup --leaves -q --all | xargs repoquery --installed --qf '%{nvra} - %{yumdb_info.reason}' | grep -- '- dep' | sed "s/\s.*$//"); a=($array); if [ ${#a[@]} -gt "0" ]; then for i in "${array[@]}"; do yumdb set reason user $i; done; fi
    

    【讨论】:

      猜你喜欢
      • 2021-02-10
      • 2022-12-14
      • 2019-01-22
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      • 2020-03-05
      • 2010-09-11
      • 1970-01-01
      相关资源
      最近更新 更多