apt-config: avoid APT complaints about sources backup files
Before apt-config makes a change to ubuntu.sources or another source
file, it backs up the original file by appending the .curtin.old
extension.
However, by default, APT will emit a warning when a file with an unknown
extension is present in the etc/apt/sources.list.d directory. Currently,
known extensions are .sources and .list so when APT sees our .curtin.old
files, it does emit a warning.
> N: Ignoring file 'ubuntu.sources.curtin.old' in directory
'/etc/apt/sources.list.d/' as it has an invalid filename extension
Through Dir::Ignore-Files-Silently directives, APT can be configured to
ignore (i.e., not warn) some of the files that have unknown extensions.
By default, the list includes:
apt: ensure systemd knows it runs in a chroot, when executing postinst
Since we added the --mount-proc option to unshare, the postinst script
for openssh-server (and most likely other packages) started failing with
the following error when `systemctl daemon-reload` was invoked:
> Failed to connect to bus: No data available
Before the option was added, it would simply do nothing because systemd
rightly understood it was running in a chroot.
To determine if we are running in a chroot, systemd checks if
/proc/1/root (corresponding to the init process) and / are the same
inode. If they are different, systemd assumes we are in a chroot.
However, we are running apt-get in a new PID namespace which means that
in the new namespace, apt-get gets assigned PID 1 and is therefore the
"init" process.
Now that /proc is properly mounted in the chroot, when systemd compares
/proc/1/root and /, it sees they are identical because the init process
(which is apt-get) is actually running inside the chroot.
Without the --mount-proc option, /proc/1 in the chroot would still refer
to the systemd init process (running outside the chroot), so it would
work properly.
With the SYSTEMD_OFFLINE variable, one can "force" systemd to assume
it is running in a chroot. Let's use it when running commands in a
chroot, and when the variable is not already defined.