How to make apt-get accept new config files in an unattended install of debian from Repo

aptaptitudesoftware installation

I am writing a script for a unattended install of a package that is in our repo, it is a software package with one of Debian's marked config files.
Is there any option that I can pass to apt-get/aptitude so that it accepts the new config files?

Basically I need an apt/aptitude equivalent of dpkg --force-confnew

I need to answer the following question posed while apt-get is installing with a Y


Configuration file “/opt/application/conf/XXX.conf`'

==> 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     : background this process to examine the 

The default action is to keep your current version.

Additional Info:

Also, I am passing the sudo password in a pipe to execute the command

echo "mysudopass"|sudo -S apt-get mypackage

This is flagging an error in installation when the installation is at the config interactive phase.

I am on Ubuntu 10.04
apt version: apt 0.7.25.3

Why I cannot use dpkg: These Debians are to be installed from Repo and I don't have local Debians on my machine

Best Answer

You can pass dpkg parameters to apt-get like this

apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew install pkgname1 pkgname2 ...

With --force-confdef if old config files still exist, they won't get overridden. So you probably won't use it, I'm just documenting it for others.

sudo will not ask for a password if you negate the authenticate option for the user or add the NOPASSWD tag in the specific entry. e.g.

someuser ALL = NOPASSWD: /usr/bin/apt-get
Related Question