![如何使用 yum 以零退出代码安装或升级软件包?](https://linux22.com/image/58906/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20yum%20%E4%BB%A5%E9%9B%B6%E9%80%80%E5%87%BA%E4%BB%A3%E7%A0%81%E5%AE%89%E8%A3%85%E6%88%96%E5%8D%87%E7%BA%A7%E8%BD%AF%E4%BB%B6%E5%8C%85%EF%BC%9F.png)
我正在编写一个脚本来从 URL 安装软件包。如果未安装,该脚本需要安装该软件包;如果已安装,则将现有版本强制替换为指定的 RPM。不幸的是,如果包已经是正确的版本,则yum install
和返回 1。yum update
我如何告诉yum
绝对、积极地安装 RPM,并且仅在存在时返回退出代码实际错误?
答案1
我不会让脚本调用yum
进行下载和安装,而是让脚本下载文件(使用例如curl
或wget
),然后强制安装下载的.rpm
文件:
rpm --install --force file_name.rpm
正如OP所示,rpm
可以直接下载URL,没有问题。从手册页:
INSTALLING, UPGRADING, AND REMOVING PACKAGES:
rpm {-i|--install} [install-options] PACKAGE_FILE ...
rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...
rpm {-F|--freshen} [install-options] PACKAGE_FILE ...
<snip>
In these options, PACKAGE_FILE can be either rpm binary file or ASCII
package manifest (see PACKAGE SELECTION OPTIONS), and may be specified
as an ftp or http URL, in which case the package will be downloaded
before being installed. See FTP/HTTP OPTIONS for information on rpm's
internal ftp and http client support.