53

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
computer.

  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?

1

5 Answers 5

55

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
1
  • 2
    If you're using sudo be sure to put it after sudo, eg sudo DEBIAN_FRONTEND=noninteractive apt-get install ...
    – altschuler
    Oct 3, 2022 at 21:10
5

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
3

This one will work like charm; add those couple lines of code before your command:

  echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
  sudo apt-get install -y -q
2
  • Are you really suggesting to modify file permission to 777 !?!? It will be readable, writable and executable by all users and may pose a huge security risk!
    – MatsK
    Aug 20, 2021 at 21:31
  • It's true, I made an update. Thanks useful insight Aug 22, 2021 at 19:58
2

"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.

3
  • This package is being installed as part of an apt-get install .... run after the initial debootstrap.
    – fadedbee
    Jan 26, 2017 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. Jan 26, 2017 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/… Jan 27, 2017 at 3:53
2

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
do 
    if [ "$(tac testfile | grep -m 1 .)" = "Country of origin for the keyboard" ]
    then 
    xdotool type <number you want to put> && xdotool key Return && break
    fi
done  

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.

2
  • 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, 2017 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, 2017 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .