Bug#983425: debconf: please add support for DPKG_ROOT

2021-06-22 Thread Johannes Schauer Marin Rodrigues
Quoting Johannes 'josch' Schauer (2021-02-24 01:44:00)
> However, with the changes from above commits, the command will succeed.

while it will succeed, it will still not reproduce the desired result. Helmut
and I now have a set of scripts that compare a chroot created with DPKG_ROOT to
one without. With the patch above, the following will be printed when one sets
DEBCONF_DEBUG=developer:

Preparing to unpack .../libc6_2.31-12+dpkgroot1_amd64.deb ...
debconf (developer): frontend started
debconf (developer): Trying to find a templates file..
debconf (developer): Trying 
/tmp/mmdebstrap.Jo8V8wNPO_//var/lib/dpkg/tmp.ci/preinst.templates
debconf (developer): Trying /usr/share/debconf/templates/preinst.templates
debconf (developer): Couldn't find a templates file.
debconf (developer): frontend running, package name is 
debconf (developer): starting 
/tmp/mmdebstrap.Jo8V8wNPO_//var/lib/dpkg/tmp.ci/preinst install

The following patch fixes the situation:

diff -Nru debconf-1.5.75/frontend debconf-1.5.75+nmu1/frontend
--- debconf-1.5.75/frontend 2021-02-28 18:51:28.0 +0100
+++ debconf-1.5.75+nmu1/frontend2021-06-22 13:28:25.0 +0200
@@ -44,10 +44,10 @@
# Avoid spurious title updates with triggered actions:
$no_title=1 if $action eq 'triggered';
 }
-elsif (-e "/var/lib/dpkg/tmp.ci/control") {
+elsif (-e "$ENV{DPKG_ROOT}/var/lib/dpkg/tmp.ci/control") {
# The preinst is running, presumably. Now it gets really ugly, because
# I have to parse the control file.
-   open (CONTROL, "< /var/lib/dpkg/tmp.ci/control")
+   open (CONTROL, "< $ENV{DPKG_ROOT}/var/lib/dpkg/tmp.ci/control")
|| die "Debconf: unable to open control file: $!";
while () {
if (/^Package: (.*)/) {
EOF

Is it desirable that debconf succeeds even if it cannot find the templates file
and cannot figure out the package name?

Thanks!

cheers, josch

signature.asc
Description: signature


Bug#983425: debconf: please add support for DPKG_ROOT

2021-02-23 Thread Johannes 'josch' Schauer
Package: debconf
Version: 1.5.74
Severity: wishlist
Tags: patch
User: debian-d...@lists.debian.org
Usertags: dpkg-root-support

Hi,

since dpkg 1.18.5, dpkg sets the variable DPKG_ROOT when invoking
maintainer scripts. Usually that variable is empty but when calling dpkg
with --root and --force-script-chrootless, dpkg will set DPKG_ROOT to
the new root directory. In that mode, maintainer scripts are called
without chroot(1) around them, and thus have to be able to possibly
operate on the path from DPKG_ROOT instead of working on /. This is
useful for bootstrapping, creating chroots for foreign architectures
where utilities from inside the chroot cannot be executed, avoiding
dependency loops between postinst scripts, installation without
requiring superuser privileges and for creating installations that do
not even contain dpkg. See
https://wiki.debian.org/Teams/Dpkg/Spec/InstallBootstrap for more
information.

Currently, missing support for DPKG_ROOT in debconf is the single
biggest blocker in making all Essential:yes packages successfully
install with --root and --force-script-chrootless. Me and Helmut Grohne
happened to work on adding DPKG_ROOT support to debconf at the same
time, so now we have two patches which both work.

helmut: 
https://salsa.debian.org/josch/debconf/-/commit/4336c589fd6cb25e20f1753986bc86a74b668846

josch: 
https://salsa.debian.org/josch/debconf/-/commit/b84d965da3c56f33fed7e4f0899bc21c34578fcd

Could you review either and give us feedback so that we can prepare a
patch that is fit for inclusion into debconf?

To try it out, you have to install the changed debconf package directly
on your machine and *not* into the chroot, because in chrootless mode,
the maintainer script will call the tools as they are installed on the
machine running it. You can see how it currently fails by running:

mmdebstrap --mode=chrootless --variant=custom --include=debconf unstable 
/dev/null
[...]
Setting up debconf (1.5.74) ...
debconf: DbDriver "passwords" warning: could not open 
/var/cache/debconf/passwords.dat: Permission denied
debconf: DbDriver "config": could not write /var/cache/debconf/config.dat-new: 
Permission denied
dpkg: error processing package debconf (--configure):
 installed debconf package post-installation script subprocess returned error 
exit status 1
Errors were encountered while processing:
 debconf
E: Sub-process /usr/bin/dpkg returned an error code (1)

However, with the changes from above commits, the command will succeed.

Thanks!

cheers, josch