brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: apt with force-confold keeps your edited config files in unattended upgrades

Apt
~/tips/tip-apt-force-confold-noninteractive

-o Dpkg::Options::="--force-confold" upgrade

Stops apt from asking about changed config files during scripted upgrades.

When a package update brings a new version of a config file you changed, dpkg stops and asks what to do. In a script or over a flaky SSH session, that question hangs everything.

Tell dpkg the answer in advance:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
  -o Dpkg::Options::="--force-confdef" \
  -o Dpkg::Options::="--force-confold" upgrade

--force-confold keeps your current file when you changed it and the package’s version changed too. Adding --force-confdef makes dpkg take the default action where there is one, which for files you never touched means quietly installing the new version. DEBIAN_FRONTEND=noninteractive silences the debconf questions some packages ask, which is a separate kind of prompt.

This is the combination I’d use for automated upgrades of servers where config lives in version control or Ansible.

Keeping the old file has a price. The new default config from the package is saved next to yours as .dpkg-dist, and new settings in it don’t reach you. Every now and then it is worth looking for them:

find /etc -name '*.dpkg-dist' -o -name '*.dpkg-new'

Compare them with your files, take over what matters and delete the leftovers. Otherwise an option that the new version needs may be missing from your config for years.

Further reading: dpkg(1) manual page (–force-confold), apt.conf(5) manual page

More Apt tips sudo apt-mark minimize-manual apt list '~c' grep -E ' (install|upgrade|remove) ' /var/log/dpkg.log | tail sudo apt-get -d -y full-upgrade apt show nginx All Apt tips (42) All topics

Link