Bug#983412: libc-bin: please add support for DPKG_ROOT to the postinst

2021-08-20 Thread Johannes Schauer Marin Rodrigues
Hi,

Quoting Johannes 'josch' Schauer (2021-02-23 20:30:41)
> this is a followup on
> 
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=910685

we can now verify that with this patch it is possible to create a Debian chroot
that is bit-by-bit identical to one created the normal way:

https://salsa.debian.org/helmutg/dpkg-root-demo/-/jobs

Currently, half the time in our CI job is spent building glibc. It would be
great if this patch can be applied, so that we do not have to build a patched
glibc anymore.

I opened a merge request here:

https://salsa.debian.org/glibc-team/glibc/-/merge_requests/4

And attached the git-format-patch.

Thanks!

cheers, josch>From 64e9212385a7cf75a206481e539ca1779a075b5e Mon Sep 17 00:00:00 2001
From: Johannes Schauer Marin Rodrigues 
Date: Fri, 20 Aug 2021 11:37:16 +0200
Subject: [PATCH] More support for DPKG_ROOT (closes: #983412)

 - this partially reverts 9e77b114 because debconf is patched to support
   DPKG_ROOT
---
 debian/changelog  | 4 
 debian/debhelper.in/libc-bin.postinst | 6 +++---
 debian/debhelper.in/libc.postinst | 2 +-
 debian/debhelper.in/libc.preinst  | 6 +++---
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index f9175ced..e6b256d9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,7 +1,11 @@
 glibc (2.31-17) UNRELEASED; urgency=medium
 
+  [ Samuel Thibault ]
   * debian/testsuite-xfail-debian.mk: Update tests.
 
+  [ Johannes Schauer Marin Rodrigues ]
+  * additional bits to support DPKG_ROOT (closes: #983412)
+
  -- Samuel Thibault   Wed, 18 Aug 2021 23:04:08 +0200
 
 glibc (2.31-16) unstable; urgency=medium
diff --git a/debian/debhelper.in/libc-bin.postinst b/debian/debhelper.in/libc-bin.postinst
index 802a3ad0..7fc320c5 100644
--- a/debian/debhelper.in/libc-bin.postinst
+++ b/debian/debhelper.in/libc-bin.postinst
@@ -40,15 +40,15 @@ update_to_current_default() {
 }
 
 if [ "$1" = "configure" ] && [ "$2" = "" ] ; then
-  install_from_default /usr/share/libc-bin/nsswitch.conf /etc/nsswitch.conf
+  install_from_default "$DPKG_ROOT/usr/share/libc-bin/nsswitch.conf" "$DPKG_ROOT/etc/nsswitch.conf"
 fi
 
 if [ "$1" = "configure" ] && [ "$2" != "" ]; then
-  update_to_current_default /usr/share/libc-bin/nsswitch.conf /etc/nsswitch.conf
+  update_to_current_default "$DPKG_ROOT/usr/share/libc-bin/nsswitch.conf" "$DPKG_ROOT/etc/nsswitch.conf"
 fi
 
 if [ "$1" = "triggered" ] || [ "$1" = "configure" ]; then
-  ldconfig || ldconfig --verbose
+  ldconfig -r "$DPKG_ROOT/" || ldconfig --verbose -r "$DPKG_ROOT/"
   exit 0
 fi
 
diff --git a/debian/debhelper.in/libc.postinst b/debian/debhelper.in/libc.postinst
index 687ebc4c..d58771ed 100644
--- a/debian/debhelper.in/libc.postinst
+++ b/debian/debhelper.in/libc.postinst
@@ -20,7 +20,7 @@ then
 __NOHWCAP__
 fi
 
-if [ "$type" = configure -a -z "$DPKG_ROOT" ]
+if [ "$type" = configure ]
 then
 # Load debconf module if available
 if [ -f /usr/share/debconf/confmodule ] ; then
diff --git a/debian/debhelper.in/libc.preinst b/debian/debhelper.in/libc.preinst
index 9a857c9c..75519bca 100644
--- a/debian/debhelper.in/libc.preinst
+++ b/debian/debhelper.in/libc.preinst
@@ -12,7 +12,7 @@ kernel_compare_versions () {
 test $verA -$2 $verB
 }
 
-if [ "$type" != abort-upgrade -a -z "$DPKG_ROOT" ]
+if [ "$type" != abort-upgrade ]
 then
 # Load debconf module if available and usable
 if [ -f /usr/share/debconf/confmodule ]; then
@@ -159,7 +159,7 @@ then
 fi
 fi
 
-if [ "$type" = upgrade -a -z "$DPKG_ROOT" ]
+if [ "$type" = upgrade ]
 then
 if [ -n "$preversion" ] && [ -x "$(command -v ischroot)" ] && ! ischroot; then
 	# NSS authentication trouble guard
@@ -247,7 +247,7 @@ then
 
 # This will keep us from using hwcap libs (optimized) during an
 # upgrade.
-touch /etc/ld.so.nohwcap
+touch "$DPKG_ROOT/etc/ld.so.nohwcap"
 fi
 
 #DEBHELPER#
-- 
2.30.2



signature.asc
Description: signature


Bug#983412: libc-bin: please add support for DPKG_ROOT to the postinst

2021-02-23 Thread Johannes 'josch' Schauer
Package: libc-bin
Version: 2.31-9
Severity: wishlist
Tags: patch
User: debian-d...@lists.debian.org

Dear maintainers,

this is a followup on

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=910685

and makes libc-bin work with DPKG_ROOT set. Namely, the call to ldconfig
has to respect "$DPKG_ROOT" as it would otherwise attempt to modify the
real root instead of the new root directory.

Note, that this is again not a full solution because this will only work
when building a similar architecture chroot. It is still an improvement
of the status quo and having DPKG_ROOT work for same-architecture
chroots is already useful.

To test, I run:

mmdebstrap --mode=chrootless --variant=custom 
--include=bsdutils,coreutils,debianutils,diffutils,dpkg,findutils,grep,gzip,hostname,init-system-helpers,ncurses-base,ncurses-bin,perl-base,sed,tar,libc-bin
 unstable /dev/null

Without the patch this fails with:

ldconfig: Can't create temporary cache file /etc/ld.so.cache~: Permission denied

With the patch above command succeeds. The patch:

diff --git a/debian/debhelper.in/libc-bin.postinst 
b/debian/debhelper.in/libc-bin.postinst
index 802a3ad0..7fc320c5 100644
--- a/debian/debhelper.in/libc-bin.postinst
+++ b/debian/debhelper.in/libc-bin.postinst
@@ -40,15 +40,15 @@ update_to_current_default() {
 }
 
 if [ "$1" = "configure" ] && [ "$2" = "" ] ; then
-  install_from_default /usr/share/libc-bin/nsswitch.conf /etc/nsswitch.conf
+  install_from_default "$DPKG_ROOT/usr/share/libc-bin/nsswitch.conf" 
"$DPKG_ROOT/etc/nsswitch.conf"
 fi
 
 if [ "$1" = "configure" ] && [ "$2" != "" ]; then
-  update_to_current_default /usr/share/libc-bin/nsswitch.conf 
/etc/nsswitch.conf
+  update_to_current_default "$DPKG_ROOT/usr/share/libc-bin/nsswitch.conf" 
"$DPKG_ROOT/etc/nsswitch.conf"
 fi
 
 if [ "$1" = "triggered" ] || [ "$1" = "configure" ]; then
-  ldconfig || ldconfig --verbose
+  ldconfig -r "$DPKG_ROOT/" || ldconfig --verbose -r "$DPKG_ROOT/"
   exit 0
 fi
 

Note, that adding DPKG_ROOT is not strictly necessary for
update_to_current_default because currently, DPKG_ROOT will only be used
for initial installations and not for upgrades.

Thanks!

cheers, josch