如何以非交互方式执行 apt-get dist-upgrade?

如何以非交互方式执行 apt-get dist-upgrade?

我在 Ubuntu 20.04 上使用以下命令:

DEBIAN_FRONTEND=noninteractive UCF_FORCE_CONFFOLD=1 apt-get -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold -y --allow-downgrades --allow-remove-essential --allow-change-held-package dist-upgrade

然而在此过程中我收到了2个对话框提示:

kdump 工具

grub-efi

我花了几个小时尝试寻找答案,找到了类似这样的页面,但不幸的是,解决方案并不能阻止这些对话框:https://serverfault.com/questions/48724/100-non-interactive-debian-dist-upgrade

在 grub-efi 的情况下如何自动选择第一项,在 kdump-tools 的情况下如何自动选择“是”?

答案1

设置 debconf 参数的命令如下:

echo "grub-pc grub-pc/install_devices multiselect /dev/sda1" | sudo debconf-set-selections

然而,为了让事情变得更清晰一些,我最终得到了这个 Ruby 代码:

debconf_rules = {
  'grub-pc' => [
    'install_devices multiselect /dev/sda1',
    'postrm_purge_boot_grub boolean false'
  ],
  'grub-efi' => 'install_devices multiselect /dev/sda1',
  'kdump-tools' => 'use_kdump boolean true',
  'postgresql-15' => 'postrm_purge_data boolean true'
}

# e.g. echo "grub-pc grub-pc/install_devices multiselect /dev/sda1" | sudo debconf-set-selections
debconf_rules.each do |package, rules|
  rules = [rules] unless rules.is_a?(Array)
  rules.each do |rule|
    puts "Setting DPKG Rule: #{package} #{package}/#{rule}"
    `echo "#{package} #{package}/#{rule}" | sudo debconf-set-selections`
  end
end

答案2

debconf-set-selections <<< "grub-efi grub-efi/install_devices multiselect /dev/sda1"
debconf-set-selections <<< "kdump-tools kdump-tools/install_kdump boolean true"

相关内容