set DPkg::Chroot-Directory in APT_CONFIG so that hooks calling apt from outside do not have to manually add it with -o

Thanks: Helmut Grohne
This commit is contained in:
Johannes Schauer Marin Rodrigues 2023-03-22 09:27:11 +01:00
parent 81d155cac8
commit 32fa6ff7bd
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1
3 changed files with 8 additions and 4 deletions

View file

@ -10,6 +10,7 @@ TARGET="$1"
if [ "${MMDEBSTRAP_MODE:-}" = "chrootless" ]; then if [ "${MMDEBSTRAP_MODE:-}" = "chrootless" ]; then
APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get --yes install \ APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get --yes install \
-oDPkg::Chroot-Directory= \
-oDPkg::Options::=--force-not-root \ -oDPkg::Options::=--force-not-root \
-oDPkg::Options::=--force-script-chrootless \ -oDPkg::Options::=--force-script-chrootless \
-oDPkg::Options::=--root="$TARGET" \ -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-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)" dpkg --compare-versions "1" "lt" "$(dpkg-query --showformat '${Version}\n' --show usr-is-merged)"
else 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 '${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$' 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)" dpkg --compare-versions "1" "lt" "$(chroot "$TARGET" dpkg-query --showformat '${Version}\n' --show usr-is-merged)"

View file

@ -1116,6 +1116,8 @@ sub run_apt_download_progress {
"-oDebug::NoLocking=1", "-oDebug::NoLocking=1",
# no need for pty magic if we write no log # no need for pty magic if we write no log
"-oDpkg::Use-Pty=0", "-oDpkg::Use-Pty=0",
# unset this or otherwise "cat >&$fd" will fail
"-oDPkg::Chroot-Directory=",
), ),
@{ $options->{APT_ARGV} }, @{ $options->{APT_ARGV} },
], ],
@ -2007,6 +2009,7 @@ sub run_setup() {
print $conf "Apt::Architectures \"$options->{nativearch}\";\n"; print $conf "Apt::Architectures \"$options->{nativearch}\";\n";
} }
print $conf "Dir \"$options->{root}\";\n"; print $conf "Dir \"$options->{root}\";\n";
print $conf "DPkg::Chroot-Directory \"$options->{root}\";\n";
# not needed anymore for apt 1.3 and newer # not needed anymore for apt 1.3 and newer
print $conf print $conf
"Dir::State::Status \"$options->{root}/var/lib/dpkg/status\";\n"; "Dir::State::Status \"$options->{root}/var/lib/dpkg/status\";\n";
@ -2902,6 +2905,7 @@ sub run_essential() {
# Example: if the host has --path-exclude set, then this will also # Example: if the host has --path-exclude set, then this will also
# affect the chroot. See #808203 # affect the chroot. See #808203
my @chrootless_opts = ( my @chrootless_opts = (
'-oDPkg::Chroot-Directory=',
'-oDPkg::Options::=--force-not-root', '-oDPkg::Options::=--force-not-root',
'-oDPkg::Options::=--force-script-chrootless', '-oDPkg::Options::=--force-script-chrootless',
'-oDPkg::Options::=--root=' . $options->{root}, '-oDPkg::Options::=--root=' . $options->{root},
@ -3025,6 +3029,7 @@ sub run_install() {
if ($options->{mode} eq 'chrootless') { if ($options->{mode} eq 'chrootless') {
if (scalar @pkgs_to_install > 0) { if (scalar @pkgs_to_install > 0) {
my @chrootless_opts = ( my @chrootless_opts = (
'-oDPkg::Chroot-Directory=',
'-oDPkg::Options::=--force-not-root', '-oDPkg::Options::=--force-not-root',
'-oDPkg::Options::=--force-script-chrootless', '-oDPkg::Options::=--force-script-chrootless',
'-oDPkg::Options::=--root=' . $options->{root}, '-oDPkg::Options::=--root=' . $options->{root},
@ -3078,8 +3083,6 @@ sub run_install() {
$options->{mode} eq 'fakechroot' $options->{mode} eq 'fakechroot'
? ('-o', 'DPkg::Install::Recursive::force=true') ? ('-o', 'DPkg::Install::Recursive::force=true')
: (), : (),
'-o',
"DPkg::Chroot-Directory=$options->{root}",
'--yes', '--yes',
'install' 'install'
], ],

View file

@ -4,6 +4,6 @@ export LC_ALL=C.UTF-8
trap "rm -f /tmp/debian-chroot.tar" EXIT INT TERM trap "rm -f /tmp/debian-chroot.tar" EXIT INT TERM
{{ CMD }} --mode={{ MODE }} --variant=essential --include=apt \ {{ 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 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 }} {{ DIST }} /tmp/debian-chroot.tar {{ MIRROR }}
tar -tf /tmp/debian-chroot.tar | sort | grep -v ./var/lib/apt/extended_states | diff -u tar1.txt - tar -tf /tmp/debian-chroot.tar | sort | grep -v ./var/lib/apt/extended_states | diff -u tar1.txt -