【问题标题】:Failing an RPM install programmatically in a spec step在规范步骤中以编程方式安装 RPM 失败
【发布时间】:2010-10-27 20:28:46
【问题描述】:

我正在制作 RPM。这个特定的 RPM 有不能用 RPM 的先决条件来表达的要求,让我们称它们为特定的文件系统/磁盘配置。目前,失败发生在安装后,在运行时,当不满足要求时。

我可以在脚本的 %install 部分检查所需的先决条件。但是,如果满足某些条件,我不知道如何使安装失败。是否可以通过 %install (或其他)部分中的某些触发器在运行时使 rpm 安装失败?

在 .spec 文件中的示例如下所示:

%install
if [ -f /some/file ]
then
    FAIL_RPM_INSTALL ## What is this command?
fi

【问题讨论】:

    标签: fedora rpm


    【解决方案1】:

    事实证明,如果您在%pre 阶段退出,rpm 安装将失败。

    %pre
    if [ -f /some/file ]
    then
        echo "/some/file exists, it shouldn't"
        exit 1
    fi
    

    参考:https://fedoraproject.org/wiki/Packaging:ScriptletSnippets

    【讨论】:

      【解决方案2】:
      %pre
      df /data|awk 'END{if ($2 < 10000000) exit 1;}'; 
      if [ $? == 1 ]; 
          then echo ERROR not enough space;exit 1;
      fi
      

      【讨论】:

      • awk 会在 file system 名称太长时给你错误的值。我相信使用df -P 可以避免这个问题。
      猜你喜欢
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-17
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      相关资源
      最近更新 更多