yum 安装多个软件包需要全部成功

yum 安装多个软件包需要全部成功

在 centos 7 (docker) 上,我看到yum install带有多个软件包的命令成功,即使某些软件包未找到。这对于脚本编写来说很糟糕:-(

(在此示例中golang未找到,因为我没有添加 EPEL 存储库)

[root@1ec73c6c476b /]# yum install golang nano
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: centos.interhost.net.il
 * extras: centos.interhost.net.il
 * updates: centos.interhost.net.il
No package golang available.
Resolving Dependencies
--> Running transaction check
---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================
 Package                                    Arch                                         Version                                             Repository                                  Size
==============================================================================================================================================================================================
Installing:
 nano                                       x86_64                                       2.3.1-10.el7                                        base                                       440 k

Transaction Summary
==============================================================================================================================================================================================
Install  1 Package

Total download size: 440 k
Installed size: 1.6 M
Is this ok [y/d/N]: y
Downloading packages:
nano-2.3.1-10.el7.x86_64.rpm                                                                                                                                           | 440 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nano-2.3.1-10.el7.x86_64                                                                                                                                                   1/1 
  Verifying  : nano-2.3.1-10.el7.x86_64                                                                                                                                                   1/1 

Installed:
  nano.x86_64 0:2.3.1-10.el7                                                                                                                                                                  

Complete!

[root@1ec73c6c476b /]# echo $?
0

如果所有指定的包都丢失,它仅退出 0:

[root@1ec73c6c476b /]# yum install foo
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: centos.interhost.net.il
 * extras: centos.interhost.net.il
 * updates: centos.interhost.net.il
No package foo available.
Error: Nothing to do

[root@1ec73c6c476b /]# yum install golang foo
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: centos.interhost.net.il
 * extras: centos.interhost.net.il
 * updates: centos.interhost.net.il
No package golang available.
No package foo available.
Error: Nothing to do

根据https://access.redhat.com/solutions/321603,根据此变更日志,后一种行为是 RHEL 6 中的新行为:https://github.com/rpm-software-management/yum/blob/master/ChangeLog#L3749-L3762

... 如果全部软件包“未找到”,yum 将消息“Nothing to do”转换为错误(返回 1,atm)。 ...因此:

  1. yum install -y a b && echo worked
    这将回显“工作”如果任何一个a 或 b 在 yum 完成后安装,但尝试同时安装两者。
  2. yum install a && yum install b && echo worked
    如果两者都安装了(如果 a 不可用,b 甚至不会尝试安装),这将回显“worked”。

但据推测,单个yum install a b更快,并且在复杂情况下比yum install a && yum install b(?)

问:是否有任何标志/配置可以在一次 yum 调用中安装多个软件包,需要全部找到成功?

答案1

将 yum 配置选项设置skip_missing_names_on_install为 false 可以解决此问题,并允许使用单个yum命令安装多个软件包,但如果缺少其中任何一个软件包,仍然会失败。

相关内容