This question already has answers here:
Is it possible to answer dialog questions when installing under docker?
(7 answers)
Closed last year.
I am making a Dockerfile and want to install xfce4. This is what I am currently trying:
RUN /bin/bash -c 'echo y 12 4 2 | apt install xfce4'
During installation, I am first prompted by a yes or no for installation. Then, I am prompted to give my geographical location (for some reason) and my timezone. Additionally, I am prompted to choose between gdm3 and lightdm. I am trying to pass these choices by echoing my choices and piping the output into stdin. This works for the yes or no, but fails for the rest. Any ideas on how to do this? Thanks.
Use:
DEBIAN_FRONTEND=noninteractive apt-get install -y xfce4
to install something non-interactively.
Related
This question already has answers here:
How to find Linux Distribution name using shell script?
(7 answers)
Closed 2 years ago.
I have an issue where I need to install package updates on ec2s, yet I wouldn't know if it is either ubuntu, or RHEL, CentOs, and AmazonLinux2.
the update for ubuntu command is:
'sudo apt-get update -y',
'sudo apt-get upgrade -y',
while the RHEL, CentOS and AmazonLinux2 update command is:
'sudo yum update -y',
I want to use command cat /etc/os-release to find out the name then put commands into an if statement to execute the appropriate update command for the OS. However, the output is printed and I have no idea how to take the name argument to use in my if statement. Any help is appreciated.
source /etc/os-release
echo "$NAME"
Output:
Ubuntu
or
Red Hat Enterprise Linux Server
There are ways to automatically answer -y in bash commands for example like
RUN apt-get install -y nodejs
but I'm having this case I want to run
dpkg --install someDebianpackage.deb && apt install --assume-yes --fix-broken
It actually answers y for the immediate prompt given by it but in the later stage it asks me to configure geographic are with answer 6
and after that again I want to answer the command with 20 for the city corresponding to timezone
and then again with answer 31 and then 1 as same as above for different questions.
What I want to know is to run this command as single command in a non-interactive way. ( I'm hoping to make a docker file and put the above command along with some other commands that can be chained with && in a RUN Command for example like
RUN apt-get update && apt-get install sudo && "the above command along with their answers" && "some other command"
I would highly appreciate some guidance over this
Technically, you can auto-answer prompts with a tool like expect. However, that's usually much more difficult than getting the program to stop asking you questions.
I'm not sure why apt is asking for your timezone, but I suspect that you're pulling in the tzdata package somehow, which wants to configure your timezone. To avoid these questions, you should set the frontend to non-interactive:
To run dpkg (behind other tools like Apt) without interactive
dialogue, you can set one environment variable as
DEBIAN_FRONTEND=noninteractive
(Source.)
In a Dockerfile, you can set an environment variable like this:
ENV DEBIAN_FRONTEND=noninteractive
I installed the 'preupg' command using:
yum -y install redhat-upgrade-tool preupgrade-assistant-contents
And I want to run the following command:
preupg
It asks if I want to continue, but I am using docker and cant say yes or no so it exits. Is there a way to silence this command?
I have tried -f and -q
To run the "preupg" tool without user interaction use
preupg --force
this will not ask for permissions and assume yes for every question.
As the preupg man page says
--force
Suppress user interaction.
I am using CentOS 6.3.
How can I ignore or write 'y' when the terminal prompts a question?
For example, when I run 'yum install java-1.7.0-openjdk', it prompts me with this statement
Is this ok [y/N]:
Is there anyway I could ignore or always say yes to the question?
In the case of yum it takes an option -y that answers yes to all questions asked.
yum -y install java-1.7.0-openjdk
For other installations you can try to pipe the command yes to the process but I'm not sure it would work with every program. Try it first.
yes | yum install java-1.7.0-openjdk
Yes, you can use Spawn.
#!/usr/bin/expect -f
spawn yum install java-1.7.0-openjdk
expect "[y/N]:"
send "y\r"
interact
I'm not tested but I found "auto-terminal" here
When I install packages in linux environment I can set the automatic 'yes' option, for example
yum -y install ...
or
apt-get -y install...
Is there a way to do the same but for ".run" programs. For example as,
sudo sh a.run -y
So that whenever it asks yes/no it automatically selects yes, whenever it asks for ok/cancel it selects ok, and so on...
thanks a lot in advance!!!
No, a .run command is simply a set of commands that are going to be run by sh. A particular .run file might take a -y option but in general you can't count on it. If you need to automate some stuff, consider using Expect.