If I'm writing a Debian package maintainer script (such as a pre-install script) for a package I create, how can I make the script determine if it is supposed to be running in non-interactive mode (e.g. if apt-get install was invoked with -y, and things like that)?
1 Answer
If your maintainer scripts need to interact with the user running the installation, the recommended way to proceed is to use debconf; see Conditional file and directory installation in Debian Packages for pointers. This might seem complicated but it does bring a number of benefits — not only does debconf handle non-interactive setups (with an explicit DEBIAN_FRONTEND=noninteractive invocation, or because there is no way to interact with a user), it also supports various frontends, and settings managed by debconf can be set ahead of installation (using “pre-seeding”). This might not be relevant in your case but debconf also supports prompts in various languages.
Note that apt-get flags are separate from maintainer script interactivity; see Is DEBIAN_FRONTEND=noninteractive redundant with apt-get -yqq?
-
Thanks for this. I switched over to debconf just now, it was rather easy and is definitely the right way to go. However, it still displays unanswered questions even if
-yis specified toapt-get, so I still have the same question: How can I skip the debconf questions and use the defaults if-yis specified?Jason C– Jason C2024-04-22 15:50:57 +00:00Commented Apr 22, 2024 at 15:50 -
1Ah, I thought “and things like that” in the question was significant. See the last link in the answer:
-ygiven toapt-getisn’t visible to maintainer scripts, you need to setDEBIAN_FRONTEND.Stephen Kitt– Stephen Kitt2024-04-22 15:55:40 +00:00Commented Apr 22, 2024 at 15:55