42

I'm trying to write a configuration script for new servers, and one of the first steps is to install a series of required packages, such as MySQL, phpMyAdmin, etc. using apt-get install However, when dpkg tries to configure them it asks you for a few options, such as MySQL root password, phpMyAdmin passwords, what server to use, etc.

Since I will likely be passing this script on to co-workers who are unlikely to read the prompts, and my desire to simply start it and walk away, I'd like to know how to pass in a series of "default" answers/values for it to use. This might include usernames/passwords/other dynamic values passed on command line.

--

I realize that having passwords in a script is a security issue, but I'm willing to ignore it, particularly in the more general sense of installing packages that an answer to this would imply.

Tarka
  • 525
  • 1
  • 4
  • 9

3 Answers3

53

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.

sebix
  • 4,313
  • 2
  • 29
  • 47
Shane Madden
  • 114,520
  • 13
  • 181
  • 251
23
export DEBIAN_FRONTEND=noninteractive
apt-get -q -y install _packages_
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Do you have a reference for what's reading $DEBIAN_FRONTEND? – Andrew Jul 13 '12 at 03:50
  • This has been a part of Debian for so long that I think only [Ian](https://en.wikipedia.org/wiki/Ian_Murdock) could really tell you when it was added. – Michael Hampton Jul 13 '12 at 04:13
  • 1
    @Andrew It's read by [debconf](http://manpages.ubuntu.com/manpages/precise/en/man7/debconf.7.html#contenttoc4), which is what actually deals with the questions. – mgorven Jul 13 '12 at 04:50
  • @mgorven Ahh, I've not gone much deeper than dpkg before. – Andrew Jul 13 '12 at 05:43
  • AFAIK, this solution only allows you skip the prompt and accept the default to all answers. If you want to set a non-default answer you have to use another solution, such as the `debconf-set-selections` method. – MestreLion Sep 21 '19 at 02:37
  • Note for Docker environments. This solution only works when called in a single line. For example, `RUN export DEBIAN_FRONTEND=noninteractive && apt-get -q -y install libglib2.0-dev`. Trying to call as 2 separate RUN commands will still show interactive prompts. – jrbe228 Mar 15 '22 at 15:45
4

The debconf package contains debconf-show:

debconf-show package
user1338062
  • 165
  • 5