Shell – Update / upgrade Debian and skip any interactions

debianraspbianshell-scriptupgradexorg

I'm running a tiny script to update and upgrade some Debian machines but since some weeks it always stopped due to some "news" the terminal is showing up. When manually upgrading I see a "fullscreen" (find screenshot below) from some software, which forces to press "q". I don't want to change any software so I'd like to find a solution, which allows to just skip every interactive screen, while upgrading.

Usually I was fine using:

sudo apt-get update -y 
sudo apt-get upgrade -y

After I realised that the upgrade process is interrupted without any timeout, I also tried to use the solution of this post:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade

but unfortunately with the same result. Does anybody have a solution to just upgrade a machine without any interruptions?

xorg-server, press q to quit

UPDATE:

First I just executed:

DEBIAN_FRONTEND=noninteractive

Secondary edited the /etc/dpkg/dpkg.cfg file to:

# dpkg configuration file
#
# This file can contain default options for dpkg.  All command-line
# options are allowed.  Values can be specified by putting them after
# the option, separated by whitespace and/or an `=' sign.
#

# Do not enable debsig-verify by default; since the distribution is not using
# embedded signatures, debsig-verify would reject all packages.
no-debsig

# Log status changes and actions to a file.
log /var/log/dpkg.log

force-confold
force-confdef

Finally I executed:

sudo apt-get upgrade -yq

This did the trick regarding "press q to quit" – great!

I think it's also working to combine the commands executing:

DEBIAN_FRONTEND=noninteractive
sudo apt-get -o Dpkg::Options::="--force-confnew --force-confdef" --force-yes -yq upgrade

Unfortunately another similar problem shows up now:

enter image description here

Also trying to edit /etc/apt/listchanges.conf didn't work out unfortunately:

[apt]
frontend=none
email_address=root
confirm=0
save_seen=/var/lib/apt/listchanges.db
which=news

SOLUTION:

I noticed (sorry if this is obvious for an advanced linux user) that bash acts different, when you execute a command via script than directly entering the command into the console.

All in all it was enough for my script solution to add the -yp parameter and set the DEBIAN_FRONTEND. In order to be safe, I'd edit the /etc/dpkg/dpkg.cfg file too.

#!/bin/bash
DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
apt-get -yq update
apt-get -yq upgrade

Best Answer

you should set DEBIAN_FRONTEND=noninteractive, this will stop debconf prompts from appearing.

After that, add force-confold and force-confdef to your /etc/dpkg/dpkg.cfg file. then use the -y option

sudo apt-get -y update && sudo apt-get -y upgrade

or use this command

apt-get -o Dpkg::Options::="--force-confnew --force-confdef" --force-yes -y upgrade

and if it doesn't work try

apt-get -o Dpkg::Options::="--force-confnew" --force-yes -y upgrade
Related Question