5

I am writing a shell script to install all my required applications on my Ubuntu PC in one shot (while I can take a stroll or do something else). For most applications adding -y to the end of the apt-get install statement, has worked well to avoid the need for any user involvement. My script looks something like this:

#!/bin/bash
add-apt-repository ppa:webupd8team/sublime-text-3 -y
apt-get update -y
apt-get upgrade -y
apt-get install synaptic -y
apt-get install wireshark -y

Though I no longer have to worry about Do you want to continue? [Y/n] or Press [ENTER] to continue or ctrl-c to cancel adding it, the problem is with wireshark, which requires a response to an interactive prompt as shown below:

Wireshark prompt

How can I avoid this mandatory intervention?

skrowten_hermit
  • 751
  • 4
  • 13
  • 34

2 Answers2

11

Configure the debconf database:

echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections

Then, install Wireshark:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install wireshark

You might also want to suppress the output of apt-get. In that case:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install wireshark > /dev/null
artic92
  • 3
  • 4
5

The apt/dpkg system has the ability to provide un-attended or non-interactive installs.

This involves setting the DEBIAN_FRONTEND variable to noninteractive and using -y flag. For example:

export DEBIAN_FRONTEND=noninteractive
apt-get -y install [packagename]

If you get errors, you may need to set the q option to more strongly convince dpkg you are in fact doing a non-interactive install: DEBIAN_FRONTEND=noninteractive apt-get -yq install [packagename].

In some cases it might just be easier to follow the prompts for some of the packages you install later in that same script/shell process, in that case you would want to un-export the DEBIAN_FRONTEND variable:

unset DEBIAN_FRONTEND

For pre-setting of configuration options its useful to have debconf-utils installed, which will avail the command debconf-get-selections:

sudo apt-get install debconf-utils

Resources you might find useful

  • 1
    And if you only need the setting for one command, don't export it; just set it for the one command: DEBIAN_FRONTEND=noninteractive apt-get -y install [packagename] – Wildcard May 29 '17 at 22:08
  • @Wildcard ah ok, , I'm just trying your "set variable for only one command" syntax, but this command fruit=apple echo $fruit doesn't echo "apple", it echo's "" (empty) do you know why? – the_velour_fog May 29 '17 at 22:16
  • That could make a great question in its own right. But briefly, it's because parameter expansion is done by the shell, and the "fruit" variable is not a shell variable; it's only an environment variable within the environment of the "echo" command. Compare: fruit=apple; bash -c 'echo $fruit' with fruit=apple bash -c 'echo $fruit' with fruit=apple; echo $fruit with fruit=apple echo $fruit. – Wildcard May 30 '17 at 01:17
  • If that's not clear, please write a question and link to it from here; I'd love to expand on that in a full answer. :) – Wildcard May 30 '17 at 01:18
  • 1
    @Wildcard Its not clear to me: it would be great if you could explain: https://unix.stackexchange.com/questions/367998/why-doesnt-bash-expand-this-variable-when-i-prefix-a-command-with-a-one-time-v – the_velour_fog May 30 '17 at 01:40
  • 1
    @Wildcard, @the_velour_fog so, if I want to respond with a "Yes" in the above screens, DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true apt-get install wireshark -y should do the trick for me? – skrowten_hermit Jun 01 '17 at 06:00