用debconf回答软件包安装问题

3

我有一个名为 foo 的包,它依赖于后缀(postfix)的依赖项。我试图通过使用 debconf 回答问题来自动安装 foo。 要求 foo 必须能够安装和配置所有内容,并且必须使用以下方式安装:

sudo apt-get install foo

那么像这样的东西是不可接受的:

DEBIAN_FRONTEND=noninteractive apt-get install -y foo

请注意,foo 正在安装在Ubuntu的全新安装系统上。

我尝试过的第一件事是这样的(在我的preinst脚本中):

echo "postfix postfix/mailname string your.hostname.com" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections

但是那样做没有起作用。这些问题仍然出现在安装中。

然后我尝试了这个:

echo "postfix postfix/mailname string your.hostname.com" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive apt-get install -y postfix

并且这个:

echo "postfix postfix/mailname string your.hostname.com" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive apt-get install -y postfix << _EOT
y
EOT

然后我想到:

如果将debconf-utils放在Pre-Depends中会怎样呢?但这并没有起作用。

然而,如果我按照以下方式操作(从命令行而不是preinst脚本),则安装可以无需提问地进行:

sudo apt-get install debconf-utils
echo "postfix postfix/mailname string your.hostname.com" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
sudo apt-get install foo

然而,这并不符合我所得到的要求。所以现在我陷入了困境。如果有人能找出我的错误,那将不胜感激,因为我已经寻找了一段时间,但仍未找到答案。
1个回答

1

看起来很奇怪,您不需要安装debconf-utils来设置dpkg的数据。

如果您想要防止对话框窗口,请尝试使用dpkg选项:
--force-confdef(强制保留默认选项而无需提示)
--force-confold(强制保留旧的配置文件)

最终,它将变成这样:
echo "postfix postfix/mailname string your.hostname.com" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
sudo apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" foo
我希望能够帮到您。如果不能,请在此通知我们。


我将它添加到我的预安装程序中(使用 postfix 而不是 foo)。对话框仍然出现。 - wc250
我甚至在preinst脚本中尝试了其他方法: 1)源debconf模块 2)使用db_set postfix/mailname your.hostname.com这也没有起作用。 - wc250
我明白了。那么,您能否解释一下,为什么您在问题中提供的最后一个示例不符合要求呢? - antonbormotov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接