I'm writing a script to install Ubuntu 16.04 server into a chroot jail, using debootstrap (on an Ubuntu 16.04 server machine).

During the setting up of the keyboard-configuration package it asks for the keyboard type:

Setting up keyboard-configuration (1.108ubuntu15) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring keyboard-configuration

The layout of keyboards varies per country, with some countries having multiple
common layouts. Please select the country of origin for the keyboard of this

  1. Afghani                                     48. Irish
  2. Albanian                                    49. Italian
  28. English (UK)                               75. Slovak
  29. English (US)                               76. Slovenian
  45. Icelandic                                  92. Vietnamese
  46. Indian                                     93. Wolof
  47. Iraqi
Country of origin for the keyboard: 

I want to automate this, so that it doesn't ask, and just continues with the install.

How can I do this?


From a similar StackOverflow question:

If the ENV variable DEBIAN_FRONTEND=noninteractive is set while you run apt-get install keyboard-configuration, it won't prompt for any interaction. So you can simply run:

DEBIAN_FRONTEND=noninteractive apt-get install keyboard-configuration
| improve this answer | |

This is simple to automate, you just need to set the proper debconf configuration for this package.

First install debconf-utils:

sudo apt install debconf-utils

If you've already configured the package, you can read the debconf configuration with:

debconf-get-selections | grep keyboard-configuration

If you haven't configured the package or would like to change your selections, you can do this with:

dpkg-reconfigure keyboard-configuration

Export your selections to a file

debconf-get-selections | grep keyboard-configuration > selections.conf

Copy selections.conf to the target machine and set the selections:

debconf-set-selections < selections.conf

When you install or reconfigure the package, your choices will now be selected automatically.

dpkg-reconfigure keyboard-configuration -f noninteractive
| improve this answer | |

You could use xdotool. When launching the script put & sleep <however long it takes to get to that point> && xdotool type <number you want to put> && xdotool key Return.

I have not tested this, but it should work.

Answer 2:

Run the command, but with the output redirected to a file ( > testfile ).

Open another terminal and run

while true
    if [ "$(tac testfile | grep -m 1 .)" = "Country of origin for the keyboard" ]
    xdotool type <number you want to put> && xdotool key Return && break

Then, click back on the first terminal.

Answer 3:

I think all you need to do is put the number you want in a file, testfile, and run the command with < testfile appended.

| improve this answer | |
  • Thanks, interesting idea, but it would either waste a lot of time, or occasionally freeze when the install was taking longer than expected, depending on the length of sleep used. – fadedbee Jan 25 '17 at 21:58
  • Reading the man page of xdotool - it seems to be an X windows thing. I am attempting this in a Ubuntu server environment. I'll update my question. – fadedbee Jan 25 '17 at 22:43

"debootstrap is really just a shell script" --from https://wiki.debian.org/Debootstrap

This means that you could read the script to see if there are ways to pass the info via an environment variable, supply an argument when invoking deboostrap, or create your own modified version for your specific application.

| improve this answer | |
  • This package is being installed as part of an apt-get install .... run after the initial debootstrap. – fadedbee Jan 26 '17 at 8:29
  • So, you're saying that after apt-get install deboostrap your installation paradigm does not allow for changing environmental variables or running of a customized script? Okay. – BenjaminBrink Jan 26 '17 at 23:08
  • Maybe this helps. This link shows an example of how to setup a "preeseed" file to pre-answer prompts in an Ubuntu install: askubuntu.com/questions/122505/… – BenjaminBrink Jan 27 '17 at 3:53

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.