1

Say I have a script that runs apt upgrade -y later on I'll need to manually answer these questions for different packages. How can I automatically do that?

Setting up 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

My script is able to detect the confile prompt but how should I go about answering yes automatically?

by using python-apt api I am able to detect the prompt via this funtion

def conffile(self, current, new):
    print " conffile prompt detected: %s %s" % (current, new)

    """(Abstract) Called when a conffile question from dpkg is detected."""
12
  • Why Python specifically? Is there a way to force "Yes" to any prompts when installing from apt-get (from a bash script)? tells me that apt-get -y upgrade should not prompt you at all. Commented Apr 10, 2017 at 7:14
  • Also there is the DEBIAN_FRONTEND=noninteractive environment variable. Commented Apr 10, 2017 at 7:15
  • It is imperative that I do it in python. Commented Apr 10, 2017 at 7:20
  • Then at least show us your Python code used to run the command, so we can help correct it. Commented Apr 10, 2017 at 7:23
  • OK, just a moment Commented Apr 10, 2017 at 7:25

3 Answers 3

2

Use the yes command:

yes Y | apt ...
Sign up to request clarification or add additional context in comments.

Comments

1

Since (per comment under the question) you're using Python-APT, the first way that comes to mind is using the Configuration class to set conf['APT::Get::Assume-Yes'] = True.

2 Comments

I tried it like this: conf = apt_pkg.config() conf['APT::Get::Assume-Yes'] = True I ended up getting apt_pkg.Configuration, object is not callable
That would likely be because apt_pkg.config is already an instance. The very paragraph mentioning it also says you don't need another instance. Also, I haven't tested it so it's possible the True should be a string or something.
0

For all those who were lost like me, the answer is:

import apt_pkg

apt_pkg.init_config()
apt_pkg.config.set("DPkg::Options::", "--force-confnew")

This will make apt automatically accept new config files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.