Passing default answers to apt-get package install questions?

Solution 1:

Use debconf's configuration preseeding.

Do a test install to get the values that you want:

root@test1:~# apt-get install mysql-server

..and set the root password when prompted during the install.

Then you can check what the debconf settings look like for what you just installed (you may need to install debconf-utils):

root@test1:~# debconf-get-selections | grep mysql-server
mysql-server-5.5        mysql-server/root_password_again        password
mysql-server-5.5        mysql-server/root_password      password
mysql-server-5.5        mysql-server/error_setting_password     error
mysql-server-5.5        mysql-server-5.5/postrm_remove_databases        boolean false
mysql-server-5.5        mysql-server-5.5/start_on_boot  boolean true
mysql-server-5.5        mysql-server-5.5/nis_warning    note
mysql-server-5.5        mysql-server-5.5/really_downgrade       boolean false
mysql-server-5.5        mysql-server/password_mismatch  error
mysql-server-5.5        mysql-server/no_upgrade_when_using_ndb  error

There's some noise there, but the important part is the password settings.

Then, for a fresh install, you can avoid the prompts completely by setting the password beforehand:

root@test2:~# echo "mysql-server-5.5 mysql-server/root_password_again password Som3Passw0rd" | debconf-set-selections
root@test2:~# echo "mysql-server-5.5 mysql-server/root_password password Som3Passw0rd" | debconf-set-selections
root@test2:~# apt-get install mysql-server

No prompts at all during that install.

Solution 2:

export DEBIAN_FRONTEND=noninteractive
apt-get -q -y install _packages_

Solution 3:

The debconf package contains debconf-show:

debconf-show package