30

I would like to configure ubuntu package via dpkg-reconfigure with all the values supplied via non-interactive mode (in the script).

In fact my case is firebird confiiguration (http://www.firebirdsql.org/manual/ubusetup.html), that when using command:

sudo dpkg-reconfigure firebird2.5-superclassic -freadline

asks me for the 2 values, where answers would be 'Y' and 'newpwd' .

Sample output looks like this:

sudo dpkg-reconfigure firebird2.5-superclassic -freadline
 * Firebird 2.5 superclassic server not running
Configuring firebird2.5-superclassic
------------------------------------

Accept if you want Firebird server to start automatically.

If you only need the Firebird client and there are no databases that will be served by this host, decline.

Enable Firebird server? Y


Password for firebird 2.5
-------------------------

Firebird has a special user named SYSDBA, which is the user that has access to all databases. SYSDBA can also create new databases and users. Because of this, it 
is necessary to secure SYSDBA with a password.

The password is stored in /etc/firebird/2.5/SYSDBA.password (readable only by root). You may modify it there (don't forget to update the security database too, 
using the gsec utility), or you may use dpkg-reconfigure to update both.

To keep your existing password, leave this blank.

Password for SYSDBA: 


 * Starting Firebird 2.5 superclassic server...
   ...done.
 * Firebird 2.5 superclassic server already running

I've tried here strings via bash script like this:

sudo dpkg-reconfigure firebird2.5-superclassic -f readline << EOF
Y
newpwd
EOF

However this didn't work for some reason and it asked for the values to be supplied.

Any ideas how to feed the required values to script?

11

You can always use the expect language to automate interaction with a process that expects its input on a tty. I haven't really used it before so I can't really add code here but yours is a typical use case.

UPDATE:

[Peter Butkovic] I consider pointing me to expect as a right direction, this script I ended with:

#!/usr/bin/expect

spawn dpkg-reconfigure firebird2.5-superclassic -freadline
expect "Enable Firebird server?"
send "Y\r"

expect "Password for SYSDBA:"
send "newpwd\r"

# done
expect eof
2
  • thanks for pointing me the right direction. I consider this answer as correct one as it was the easy to implement solution. Oct 16 '13 at 7:21
  • I would be wary of the possibility of i18n issues, but for "home use" this seems safe.
    – Jasen
    Feb 3 '18 at 20:16
21

Debian packages use debconf to collect installation-time settings. Debconf supports multiple frontends to prompt the user for values. The -f option to dpkg-reconfigure selects which debconf frontend to use.

The readline frontend is designed for interactive use. Don't use it in an automatic script.

If the default values are fine, then simply use the noninteractive frontend.

If you want to supply different values, you have two options. You can stick with the noninteractive frontend, and preseed the debconf database. The easiest way to do this is to install the package on one machine and configure it interactively, then extract the relevant parts from /var/cache/debconf/config.dat and supply this file to debconf:

DEBCONF_DB_OVERRIDE='File {/path/to/config.dat}' dpkg-reconfigure -fnoninteractive firebird2.5-superclassic

Another method is to use the editor frontend, and set the environment variable VISUAL (or EDITOR, but VISUAL has precedence over EDITOR if it is set) to a program that takes a file containing the current settings as an argument, and overwrites that file with the settings you want.

7
  • 6
    No need to parse /var/cache/debconf/config.dat yourself. You can use debconf-get-selections from the debconf-utils package. See this for example.
    – Joseph R.
    Oct 16 '13 at 0:43
  • Also, I'm not sure if preseeding is the right fit here. We're talking about running dpkg-reconfigure, which I'm guessing the OP wants to automate because he'll be doing it frequently.
    – Joseph R.
    Oct 16 '13 at 2:19
  • thanks for hints. decided to go for expect script. didn't investigate deeper here. Oct 16 '13 at 7:18
  • 3
    @JosephR. Indeed, debconf-get-selections is likely to be useful here. If Peter wants to do this often with different values, he should generate a config.dat dynamically (it's a simple format). This is easier than expect. expect is the path of desperation. For example, it'll break down if a new version of the package introduces a new question (or else you need a far more sophisticated script). Oct 16 '13 at 17:52
  • @JosephR the link about pre-seeding you posted no longer works, try this: zacks.eu/debian-preseed Dec 5 '18 at 20:33
17

Use debconf-set-selections command to insert new values into the debconf database (/var/cache/debconf/config.dat).


Eli answer wasn't clear for me, so I'll explain it step by step.

The first thing to do is to install package interactively and get the chosen selections by (change firebird to your package name):

sudo debconf-get-selections | grep ^firebird

or:

grep -C2 firebird /var/cache/debconf/config.dat

Then pre-seed the debconf database with answers by debconf-set-selections, for example:

echo firebird2.5-superclassic shared/firebird/enabled boolean true | sudo debconf-set-selections -v
echo firebird2.5-superclassic shared/firebird/sysdba_password/new_password password foo | sudo debconf-set-selections -v

where syntax is:

echo foo-owner-package-name foo-template-name value-type value | debconf-set-selections

Here is another example for ttf-mscorefonts-installer package:

echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections

Note: The input selections can be either from the standard input or the file.

Check: man debconf-set-selections for further info.

Note: If debconf-get-selections is not found, use

apt-get install debconf-utils

to install.


Alternative way is to use Kickstart.

4
  • 1
    debconf-set-selections doesn't seem to take effect in all cases, eg: exim.
    – Jasen
    Feb 3 '18 at 20:18
  • 1
    debconf-set-selections does NOT run the configuration script built into the deb package you are changing. It only sets the selections the package is asking for which is only the first part of it. dpkg-reconfigure runs both parts.
    – fred
    Jan 16 '19 at 20:42
  • This should be the correct answer for this question.
    – JCCyC
    Oct 24 '20 at 15:06
  • @fred I'm not sure I get it… should I run printf %s\\t%s\\t%s\\t%s\\n keyboard-configuration keyboard-configuration/ctrl_alt_bksp boolean true | sudo debconf-set-selections -v followed by sudo dpkg-reconfigure -f noninteractive keyboard-configuration ? Or is there something else to do in order to re-run the configuration script with the values that were just set? If I run sudo dpkg-reconfigure keyboard-configuration, the preselected values in the text user interface are NOT the ones that were given to debconf-set-selections, so I guess those were ignored in non-interactive mode too. Mar 8 at 2:14
5

I've been poking around for about an hour just trying to condense the solution for this down to a one-liner and I finally found it: debconf-set-selections

echo "debconf debconf/frontend select noninteractive" | sudo debconf-set-selections

This will force debconf to use the defaults and not bug you. You can also set the configuration defaults for any Debian package, see the manpage for more info.

2
  • Isn't the same as sudo dpkg-reconfigure debconf -f noninteractive or export DEBIAN_FRONTEND=noninteractive?
    – kenorb
    Nov 27 '15 at 0:59
  • No, DEBIAN_FRONTEND=noninteractive allows to accept default answers without interaction. This allows to change those answers.
    – Alek
    Mar 17 at 3:04
1

I've been attempting to do scripted reconfiguration of LDAP settings (ldap-auth-config package) using the debconf-get-selections/set-selections method mentioned above, only to find that this package ignores settings in debconf after initial installation. You can use debconf to pre-seed before install, but after install ldap-auth-config prefers to overwrite your debconf settings with whatever is set in the system config files it manages. Package pam-auth-config has the same behavior.

The EDITOR/VISUAL mechanism is also difficult to use in this case because ldap-auth-config invokes it multiple times for different sets of questions. It can be handled more easily with an expect script, or by directly modifying the system config files. So, it's not always easy to avoid falling back to expect!

0

My version of the expect solution to install the ArangoDB .deb using pexpect

import pexpect
import os

os.environ['DEBIAN_FRONTEND']= 'readline'

child = pexpect.spawnu('dpkg -i arangodb3_3.6.2-1_amd64.deb')

child.expect('user:')
child.sendline('defg')
child.expect('user:')
child.sendline('defg')
child.expect("Automatically upgrade database files")
child.sendline("yes")
child.expect("Database storage engine")
child.sendline("1")
child.expect("Backup database files before upgrading")
child.sendline("no")
child.expect(pexpect.EOF)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.