有没有一种方法可以apt-get dist-upgrade在Debian中执行,它不仅可以对所有提出的问题自动回答“是”,还可以使用合理的默认值作为对问题的答案,这些问题足够复杂,需要弹出各种交互式对话框?我在这里考虑的是升级时显示的按键图内容libc6以及内核映像选择。
目标是能够远程启动一个相当大的dist-upgrade主机,即使对于一台严重落后于时代的机器,也不必烦恼它,除非发生了可怕的灾难性错误。
当然可以吗?
提前致谢!
有没有一种方法可以apt-get dist-upgrade在Debian中执行,它不仅可以对所有提出的问题自动回答“是”,还可以使用合理的默认值作为对问题的答案,这些问题足够复杂,需要弹出各种交互式对话框?我在这里考虑的是升级时显示的按键图内容libc6以及内核映像选择。
目标是能够远程启动一个相当大的dist-upgrade主机,即使对于一台严重落后于时代的机器,也不必烦恼它,除非发生了可怕的灾难性错误。
当然可以吗?
提前致谢!
Answers:
如果设置DEBIAN_FRONTEND=noninteractive(停止出现的debconf提示),并添加force-confold和force-confdef你的/etc/dpkg/dpkg.cfg文件,你应该有一个完全非交互式软件包安装经验。任何仍然提示您提供信息的软件包都具有严重的发行错误(我说这既是自动化迷,还是Debian开发人员)。
apt-listchanges由打开less。
弗洛里安·洛霍夫(Florian Lohoff)发布了一种方法,可将建议的womble转换为单个命令:
DEBIAN_FRONTEND=noninteractive \
apt-get \
-o Dpkg::Options::="--force-confnew" \
--force-yes \
-fuy \
dist-upgrade
当然,您也可以使用-o Dpkg::Options::="--force-confnew --force-confdef"(在dpkg手册页中搜索confnew)。我不确定在什么情况下会有所作为。我个人需要进行非交互式升级以使香草图像保持最新,在这种情况下,我认为总是选择新的配置文件(不带--force-confdef)是合理的。
W: --force-yes is deprecated, use one of the options starting with --allow instead.
尽管上述womble的答案总体上不错,但它对我没有用,我不得不做一些额外的研究才能100%无人值守。我想我将以简洁的方式分享结果,以使将来的访问者更轻松。
以下是一个脚本,它将根据debian 8发行说明的升级建议(主要是)以及将使其无人值守的标志和环境变量来运行。(echos仅用于调试,可以将其删除-尽管我建议保留它们,以便如果脚本卡住了,您将知道在哪里)
#!/bin/bash
apt-get remove apt-listchanges --assume-yes --force-yes &&
#using export is important since some of the commands in the script will fire in a subshell
export DEBIAN_FRONTEND=noninteractive &&
export APT_LISTCHANGES_FRONTEND=none &&
#lib6c was an issue for me as it ignored the DEBIAN_FRONTEND environment variable and fired a prompt anyway. This should fix it
echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections &&
echo "executing wheezy to jessie" &&
find /etc/apt -name "*.list" | xargs sed -i '/^deb/s/wheezy/jessie/g' &&
echo "executing autoremove" &&
apt-get -fuy --force-yes autoremove &&
echo "executing clean" &&
apt-get --force-yes clean &&
echo "executing update" &&
apt-get update &&
echo "executing upgrade" &&
apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy upgrade &&
echo "executing dist-upgrade" &&
apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy dist-upgrade
如果你在使用APT 1.1或以上,--force-yes已被弃用,所以,你已经使用的选项开始--allow代替,例如--allow-downgrades,--allow-remove-essential,--allow-change-held-packages。
所以命令是:
DEBIAN_FRONTEND=noninteractive \
apt-get \
-o Dpkg::Options::=--force-confold \
-o Dpkg::Options::=--force-confdef \
-y --allow-downgrades --allow-remove-essential --allow-change-held-packages \
dist-upgrade
注意:--force-confold用于保留旧配置,并--force-confnew保留新配置。
来源:CFE-2360:使apt_get软件包模块版本知道。
有关:
从apt-get(8)手册页:
-y, --yes, --assume-yes
Automatic yes to prompts; assume "yes" as answer to all prompts
run non-interactively. If an undesirable situation, such as
changing a held package, trying to install a unauthenticated
package or removing an essential package occurs then apt-get will
abort. Configuration Item: APT::Get::Assume-Yes.
作为参考,该-y选项也适用yum(8)。