100% non-interactive Debian dist-upgrade

Solution 1:

If you set DEBIAN_FRONTEND=noninteractive (to stop debconf prompts from appearing) and add force-confold and force-confdef to your /etc/dpkg/dpkg.cfg file, you should have a completely noninteractive package installation experience. Any package that still prompts you for information has a release critical bug (and I say that as both an automation junkie and as a Debian developer).

Solution 2:

Florian Lohoff posted a way to get what womble suggested into a single command:

DEBIAN_FRONTEND=noninteractive \
apt-get \
-o Dpkg::Options::="--force-confnew" \
--force-yes \
-fuy \
dist-upgrade

Of course you might also use -o Dpkg::Options::="--force-confnew --force-confdef" (search the the dpkg man page for confnew). I'm not sure in what cases this would make a difference though. I personally need the non-interactive upgrade to bring vanilla images up-to-date, in which case I suppose always picking the new config file (without --force-confdef) is a reasonable thing.


Solution 3:

Even though womble's answer above is generally good, it did not work for me and I had to do some additional research to go 100% unattended. I thought I'll share the result in a concise manner to make things simpler for future visitors.

The following is a script that will run according to the debian 8 release notes upgrade recommendations (mostly) along with flags and environment variables that will make it unattended. (the echos are just for debugging and could be removed - though I recommend keeping them so if the script gets stuck you will know where)

#!/bin/bash

apt-get remove apt-listchanges --assume-yes --force-yes &&

#using export is important since some of the commands in the script will fire in a subshell
export DEBIAN_FRONTEND=noninteractive &&
export APT_LISTCHANGES_FRONTEND=none &&

#lib6c was an issue for me as it ignored the DEBIAN_FRONTEND environment variable and fired a prompt anyway. This should fix it
echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections &&

echo "executing wheezy to jessie" &&
find /etc/apt -name "*.list" | xargs sed -i '/^deb/s/wheezy/jessie/g' &&

echo "executing autoremove" &&
apt-get -fuy --force-yes autoremove &&

echo "executing clean" &&
apt-get --force-yes clean &&

echo "executing update" &&
apt-get update &&

echo "executing upgrade" &&
apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy upgrade &&

echo "executing dist-upgrade" &&
apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy dist-upgrade

Solution 4:

>= Apt 1.1

If you're using Apt 1.1 or above, --force-yes has been deprecated, so you've to use the options starting with --allow instead, e.g. --allow-downgrades, --allow-remove-essential, --allow-change-held-packages.

So the command is:

DEBIAN_FRONTEND=noninteractive \
  apt-get \
  -o Dpkg::Options::=--force-confold \
  -o Dpkg::Options::=--force-confdef \
  -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \
  dist-upgrade

Note: Use --force-confold to keep old, and --force-confnew to keep new configs.

Source: CFE-2360: Make apt_get package module version aware.

Related:

  • apt-get update non interactive
  • How do I ask apt-get to skip any interactive post-install configuration steps?
  • Non-interactive apt upgrade

Tags:

Linux

Debian

Apt