1

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?

4

You just need to set debconf selection.

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install wireshark
echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
sudo DEBIAN_FRONTEND=noninteractive dpkg-reconfigure wireshark-common
3

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 1:17
  • 1
    @Wildcard Its not clear to me: it would be great if you could explain: unix.stackexchange.com/questions/367998/… – the_velour_fog May 30 '17 at 1: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 1 '17 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.