當前位置: 首頁>>技術問答>>正文


使用-y運行apt-get(或aptitude)但不提示更換配置文件?

, ,

問題描述

在Ubuntu 10.04上運行apt-get -y install <packages ...>時,我希望apt-get(或aptitude,如果這樣更容易)在安裝其他依賴項時沒有提示我(-y的行為,據我所知)但是沒有提示我有關覆蓋配置文件,而是假設保留總是存在的(通常是默認的)。不幸的是,--trivial-only似乎與-y相反,並且不會影響顯示的提示,根據man頁麵。

特別是作為samba,nullmailer,localepurge和lighttpd的包auch強迫我與終端交互,即使整個過程是腳本化的並且意味著是non-interactive。

最佳解決方法

你可以使用:

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

僅適用於特定包裝,例如mypackage1 mypackage2:

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install mypackage1 mypackage2

資料來源:http://raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/

Avoiding the conffile prompt

Every time that dpkg must install a new conffile that you have modified
(and a removed file is only a particular case of a modified file in dpkg’s eyes),
it will stop the upgrade and wait your answer. This can be particularly annoying for
major upgrades. That’s why you can give predefined answers to dpkg with the help
of multiple --force-conf* options:

    --force-confold: do not modify the current configuration file, the new version
is installed with a .dpkg-dist suffix. With this option alone, even configuration
files that you have not modified are left untouched. You need to combine it with
--force-confdef to let dpkg overwrite configuration files that you have not modified.
    --force-confnew: always install the new version of the configuration file, the
current version is kept in a file with the .dpkg-old suffix.
    --force-confdef: ask dpkg to decide alone when it can and prompt otherwise. This
is the default behavior of dpkg and this option is mainly useful in combination with
--force-confold.
    --force-confmiss: ask dpkg to install the configuration file if it’s currently
missing (for example because you have removed the file by mistake).

If you use Apt, you can pass options to dpkg with a command-line like this:

$ apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

You can also make those options permanent by creating /etc/apt/apt.conf.d/local:

Dpkg::Options {
   "--force-confdef";
   "--force-confold";
}

您可以在http://manpages.ubuntu.com/manpages/xenial/en/man1/dpkg.1.htmlman dpkg的dpkg手冊中找到更多信息和更多選項,即查找”confdef”。

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/1328.html,未經允許,請勿轉載。