Feeding input values to dpkg-reconfigure in a non-interactive way
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.
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.
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