Skip to main content
1 of 2
Hi-Angel
  • 5.6k
  • 5
  • 32
  • 48

Making `apt-get` read answers from stdin on graphical Ubuntu

This may seem like a question asked, but I have yet to find anything that works and I start suspecting it may be a bug in apt-get

So, I have a python installer wrapping around apt-get, whose relevant functional basically amounts to:

echo -e "answer1\nanswer2\nanswer3\n" | DEBIAN_FRONTEND=teletype apt-get install foo.deb 

This works fine! In a container… Yesterday first actual end-user run this script in a graphical Ubuntu under tmux, and this broke: installation hangs waiting for user to answer questions. It does accept user input, but the user isn't supposed to answer these, installer is. But graphical Ubuntu apt-get outright ignores stdin.

What I tried so far (from what I remember):

  1. DEBIAN_FRONTEND with backends readline, teletype, text. None of them make apt-get receive answers from stdin. They do kinda work, because the previous problem was graphical Ubuntu triggering TUI — setting the variable to either of them at least bypasses that.
  2. DEBIAN_FRONTEND=noninteractive: this just randomly answers questions, which isn't desired either.
  3. Looking in both DEBIAN_FRONTEND docs and apt-get docs for keyword stdin. No avail. As a matter of fact, it even lacks some DEBIAN_FRONTEND values (it at least doesn't mention teletype, even though apt-get complains you need to use it instead of readline when in a script)
  4. Asking AI, obviously. It gave some involved PTY changing code for python with incorrectly scoped vars, and I dropped the ball. It has to be something simple; well, unless I really just stumbled upon apt-get bug here and the teletype ought to be enough.

How to reproduce

postfix is one small package with a question, so assuming it either isn't installed or purgeed away, the:

echo -e 'No configuration\n' | DEBIAN_FRONTEND=teletype apt-get install postfix 

…inside graphical Ubuntu hangs waiting for user to type-in the "No configuration".

Hi-Angel
  • 5.6k
  • 5
  • 32
  • 48