How do I answer install prompts (other than with "yes") automatically?
Asked Answered
S

2

6

Synopsis

I'm trying to build a Docker image, but it fails because one of the packages I'm trying to get with apt install prompts the user during the install process. I would like to reply to this prompt, but I can't figure out how to do it non-interactively.

Description

I'm building a Docker image, and my Dockerfile has the following line:

RUN apt install -y texlive-latex-extra

(This package has some LaTeX libraries that I need.)

During installation, this halts with:

Setting up tzdata (2018d-1) ...
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 tzdata
------------------

Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.

  1. Africa        6. Asia            11. System V timezones
  2. America       7. Atlantic Ocean  12. US
  3. Antarctica    8. Europe          13. None of the above
  4. Australia     9. Indian Ocean
  5. Arctic Ocean  10. Pacific Ocean
Geographic area:

At this point, it is waiting for some input. (There's another prompt after this for selecting timezone—I assume this is important to know for the \today directive in LaTeX files. ¯\_(ツ)_/¯)

How can I answer this non-interactively?

What I've tried so far

I've tried doing this:

apt install -y texlive-latex-extra <(echo 12 && echo 2)

and this:

echo 12 && echo 2 | apt install -y texlive-latex-extra

The first one died with this error:

apt install -y texlive-latex-extra <(echo 12 && echo 9)

and the second one seemed to have no effect.

For reference, here is my Dockerfile up until this point:

FROM ubuntu:latest

RUN apt update && apt upgrade -y && apt install -y curl bzip2 tar make gcc wget gnupg unzip
RUN apt install -y texlive
RUN apt install -y nodejs npm git
RUN npm install -g bower
RUN apt install -y texlive-latex-extra

UPDATE

I found something close here which suggested running apt install with DEBIAN_FRONTEND=noninteractive. This solved my problem sufficiently. :) However, I still would like to know how to respond to prompts, as the solution offered there only offered how to suppress them.

Silicle answered 31/8, 2018 at 4:5 Comment(0)
A
3

If you want to script a terminal interaction, you could use expect on Linux (that might not be very easy; you need to predict the interactions).

Remember that terminal emulators are complex and arcane things (because terminals like VT100 have been complex). See termios(3), pty(7) and read The Tty demystified.

Adjudicate answered 31/8, 2018 at 5:12 Comment(2)
Solid. Thanks! Could you provide an example of using expect in a case like this?Silicle
No. I forgot most of expect. Used it more than twenty years ago. In general, you should not need to use it.Adjudicate
C
1

The specific install prompt mentioned in the question is caused by the package tzdata. I managed to get it configured non-interactively in my docker build by setting these environment variables:

DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y texlive-luatex texlive-latex-extra texlive-font

I found this solution over here: https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image

Corliss answered 7/11, 2022 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.