From fd33bd2a402c4af9fab47792d08a522451026525 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Wed, 22 Mar 2023 09:27:11 +0100 Subject: [PATCH] set DPkg::Chroot-Directory in APT_CONFIG This is so that users calling apt-get install from a hook only need to have APT_CONFIG=$MMDEBSTRAP_APT_CONFIG set and do not also have to pass -oDPkg::Chroot-Directory="$1". This breaks users running apt-get with DPkg::Options::=--force-script-chrootless or with Dpkg::Pre-Install-Pkgs from within a hook with APT_CONFIG=$MMDEBSTRAP_APT_CONFIG. In those situations, DPkg::Chroot-Directory has to be set to the empty string explicitly with -o to overwrite the APT_CONFIG setting. Thanks: Helmut Grohne --- hooks/merged-usr/essential00.sh | 3 ++- mmdebstrap | 7 +++++-- ...-to-install-apt-in-include-because-a-hook-did-it-before | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hooks/merged-usr/essential00.sh b/hooks/merged-usr/essential00.sh index 2acbdba..d9a8130 100755 --- a/hooks/merged-usr/essential00.sh +++ b/hooks/merged-usr/essential00.sh @@ -10,6 +10,7 @@ TARGET="$1" if [ "${MMDEBSTRAP_MODE:-}" = "chrootless" ]; then APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get --yes install \ + -oDPkg::Chroot-Directory= \ -oDPkg::Options::=--force-not-root \ -oDPkg::Options::=--force-script-chrootless \ -oDPkg::Options::=--root="$TARGET" \ @@ -20,7 +21,7 @@ if [ "${MMDEBSTRAP_MODE:-}" = "chrootless" ]; then dpkg-query --showformat '${Source}\n' --show usr-is-merged | grep -q '^usrmerge$' dpkg --compare-versions "1" "lt" "$(dpkg-query --showformat '${Version}\n' --show usr-is-merged)" else - APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get --yes install -oDPkg::Chroot-Directory="$TARGET" usr-is-merged + APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get --yes install usr-is-merged chroot "$TARGET" dpkg-query --showformat '${db:Status-Status}\n' --show usr-is-merged | grep -q '^installed$' chroot "$TARGET" dpkg-query --showformat '${Source}\n' --show usr-is-merged | grep -q '^usrmerge$' dpkg --compare-versions "1" "lt" "$(chroot "$TARGET" dpkg-query --showformat '${Version}\n' --show usr-is-merged)" diff --git a/mmdebstrap b/mmdebstrap index 0abdfc3..d9f40bc 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -1116,6 +1116,8 @@ sub run_apt_download_progress { "-oDebug::NoLocking=1", # no need for pty magic if we write no log "-oDpkg::Use-Pty=0", + # unset this or otherwise "cat >&$fd" will fail + "-oDPkg::Chroot-Directory=", ), @{ $options->{APT_ARGV} }, ], @@ -2022,6 +2024,7 @@ sub run_setup() { print $conf "Apt::Architectures \"$options->{nativearch}\";\n"; } print $conf "Dir \"$options->{root}\";\n"; + print $conf "DPkg::Chroot-Directory \"$options->{root}\";\n"; # not needed anymore for apt 1.3 and newer print $conf "Dir::State::Status \"$options->{root}/var/lib/dpkg/status\";\n"; @@ -2878,6 +2881,7 @@ sub run_essential() { # Example: if the host has --path-exclude set, then this will also # affect the chroot. See #808203 my @chrootless_opts = ( + '-oDPkg::Chroot-Directory=', '-oDPkg::Options::=--force-not-root', '-oDPkg::Options::=--force-script-chrootless', '-oDPkg::Options::=--root=' . $options->{root}, @@ -3001,6 +3005,7 @@ sub run_install() { if ($options->{mode} eq 'chrootless') { if (scalar @pkgs_to_install > 0) { my @chrootless_opts = ( + '-oDPkg::Chroot-Directory=', '-oDPkg::Options::=--force-not-root', '-oDPkg::Options::=--force-script-chrootless', '-oDPkg::Options::=--root=' . $options->{root}, @@ -3054,8 +3059,6 @@ sub run_install() { $options->{mode} eq 'fakechroot' ? ('-o', 'DPkg::Install::Recursive::force=true') : (), - '-o', - "DPkg::Chroot-Directory=$options->{root}", '--yes', 'install' ], diff --git a/tests/not-having-to-install-apt-in-include-because-a-hook-did-it-before b/tests/not-having-to-install-apt-in-include-because-a-hook-did-it-before index 196fa2f..9a36307 100644 --- a/tests/not-having-to-install-apt-in-include-because-a-hook-did-it-before +++ b/tests/not-having-to-install-apt-in-include-because-a-hook-did-it-before @@ -4,6 +4,6 @@ export LC_ALL=C.UTF-8 trap "rm -f /tmp/debian-chroot.tar" EXIT INT TERM {{ CMD }} --mode={{ MODE }} --variant=essential --include=apt \ --essential-hook='APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get update' \ - --essential-hook='APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get --yes install -oDPkg::Chroot-Directory="$1" apt' \ + --essential-hook='APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get --yes install apt' \ {{ DIST }} /tmp/debian-chroot.tar {{ MIRROR }} tar -tf /tmp/debian-chroot.tar | sort | grep -v ./var/lib/apt/extended_states | diff -u tar1.txt -