【发布时间】:2017-04-10 07:11:21
【问题描述】:
假设我有一个稍后运行apt upgrade -y 的脚本,我需要为不同的包手动回答这些问题。我怎样才能自动做到这一点?
设置 virtualbox-guest-x11 (5.0.32-dfsg-0ubuntu1.16.04.2) ...
Configuration file '/etc/X11/Xsession.d/98vboxadd-xclient'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** 98vboxadd-xclient (Y/I/N/O/D/Z) [default=N] ? conffile prompt detected: /etc/X11/Xsession.d/98vboxadd-xclient /etc/X11/Xsession.d/98vboxadd-xclient.dpkg-new
我的脚本能够检测到配置提示,但我应该如何自动回答是?
通过使用 python-apt api,我可以通过这个功能检测到提示
def conffile(self, current, new):
print " conffile prompt detected: %s %s" % (current, new)
"""(Abstract) Called when a conffile question from dpkg is detected."""
【问题讨论】:
-
为什么是 Python? Is there a way to force "Yes" to any prompts when installing from apt-get (from a bash script)? 告诉我
apt-get -y upgrade根本不应该提示你。 -
还有
DEBIAN_FRONTEND=noninteractive环境变量。 -
我必须用python来做。
-
那么至少向我们展示您用于运行该命令的 Python 代码,以便我们帮助纠正它。
-
好的,请稍等