9.1.pkg-message(安装二进制包时显示的消息文件)

有一些关于 pkg-*文件的技巧我们还没有提到,有时候会很方便。

9.1.pkg-message(安装二进制包时显示的消息文件)

在安装软件包时显示消息,请将消息放在 pkg-message 中。这种功能通常用于显示安装后需要执行的额外步骤 pkg install 或 pkg upgrade 。

* pkg-message 必须仅包含对 FreeBSD 设置和操作至关重要且特定于相关port的信息。* 设置信息应仅在初始安装时显示。升级说明应仅在从相关版本升级时显示。* 不要用空格或符号行(如 ---------- , 或 ========== )包围消息。将格式留给 pkg(8)。* 提交者可以使用 UCL 格式规范来限制现有消息的安装或升级范围。* 请确保参考适当的工具来处理服务。 使用 service name start 来启动服务,而不是使用 /usr/local/etc/rc.d/name start * 使用 sysrc name_enable=YES 在 rc.conf 中更改选项

pkg-message 支持两种格式:

原始

一个常规的纯文本文件。它的消息只在安装时显示。

UCL

如果文件以“[”开头,则被视为 UCL 文件。UCL 格式在 libucl 的 GitHub 页面上有描述。

9.1.1. pkg-message 中的 UCL

格式如下。它应该是对象数组。这些对象本身可以具有这些关键字。

message

要显示的实际消息。此关键字是强制性的。

type

消息应该何时显示。

maximum_version

仅当 type 为 upgrade 时。如果从严格低于指定版本升级,则显示。

minimum_version

只有当 type 是 upgrade 时。如果从严格大于指定版本升级,则显示。

可以组合使用 maximum_version 和 minimum_version 关键字。

type 关键字可以有三个值:

install

只有在软件包安装时才显示消息。

remove

只有在卸载软件包时才显示消息。

upgrade

只有在升级软件包时才显示消息。

示例 1. UCL 短字符串

消息由双引号 " 分隔,用于简单的单行字符串:

[
{ type: install
  message: "Simple message"
}
]

Example 2. UCL Multiline Strings

Multiline strings use the standard here document notation. The multiline delimiter must start just after << symbols without any whitespace and it must consist of capital letters only. To finish a multiline string, add the delimiter string on a line of its own without any whitespace. The message from UCL Short Strings can be written as:

[
{ type: install
  message: <<EOM
Simple message
EOM
}
]

Example 3. Display a Message on Install/Deinstall

当消息只需要在安装或卸载时显示时,请设置类型:

[
{
  type: remove
  message: "package being removed."
}
{ type: install, message: "package being installed."}
]

例 4. 在升级时显示消息

当port升级时,显示的消息可以更加贴合port的需求。

[
{
  type: upgrade
  message: "Package is being upgraded."
}
{
  type: upgrade
  maximum_version: "1.0"
  message: "Upgrading from before 1.0 need to do this."
}
{
  type: upgrade
  minimum_version: "1.0"
  message: "Upgrading from after 1.0 should do that."
}
{
  type: upgrade
  maximum_version: "3.0"
  minimum_version: "1.0"
  message: "Upgrading from > 1.0 and < 3.0 remove that file."
}
]

在升级时显示消息时,重要的是限制向用户显示消息的时间。大多数情况下,通过使用 maximum_version 来限制其使用,以便在需要执行特定操作时将其升级到特定版本之前的升级中显示。

最后更新于

FreeBSD 中文社区