Package: netbase
Version: 6.1
Severity: normal
Tags: patch

Systems installed by d-i get such an entry, but chroots created with
debootstrap don't. That sometimes causes issues, e.g. cups fails to
build in a chroot that doesn't have an entry for the local hostname.

The attached patch makes /etc/hosts in chroots consistent with the one
in systems installed by d-i.

I tested this end-to-end by creating a fresh chroot using mmdebootstrap
and pointing to a regular debian mirror and a local repository with a
build of netbase including this patch, and it works as intended.

This is also available as a merge request on salsa:
https://salsa.debian.org/md/netbase/-/merge_requests/2

-- System Information:
Debian Release: bullseye/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'testing-debug'), (500, 
'unstable'), (500, 'testing'), (1, 'experimental-debug'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 5.7.0-2-amd64 (SMP w/4 CPU threads)
Locale: LANG=pt_BR.UTF-8, LC_CTYPE=pt_BR.UTF-8 (charmap=UTF-8), 
LANGUAGE=pt_BR:pt:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- no debconf information
From 29e597f1245c9cde862814db3aac82d4e9208daf Mon Sep 17 00:00:00 2001
From: Antonio Terceiro <terce...@debian.org>
Date: Sun, 7 Jun 2020 14:42:20 -0300
Subject: [PATCH] /etc/hosts: include entry for local hostname

Systems installed by d-i get such an entry, but chroots created with
debootstrap don't. That sometimes causes issues, e.g. cups fails to
build in a chroot that doesn't have an entry for the local hostname.

This patch makes /etc/hosts in chroots consistent with the one in
systems installed by d-i.
---
 debian/netbase.postinst | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/debian/netbase.postinst b/debian/netbase.postinst
index 4876e47..7db07de 100644
--- a/debian/netbase.postinst
+++ b/debian/netbase.postinst
@@ -3,8 +3,15 @@
 create_hosts_file() {
   if [ -e /etc/hosts ]; then return 0; fi
 
+  if [ -e /etc/hostname ]; then
+    hostnameline="127.0.1.1	$(head -1 /etc/hostname)"
+  else
+    hostnameline=""
+  fi
+
   cat > /etc/hosts <<-EOF
 	127.0.0.1	localhost
+	${hostnameline}
 	::1		localhost ip6-localhost ip6-loopback
 	ff02::1		ip6-allnodes
 	ff02::2		ip6-allrouters
-- 
2.28.0

Attachment: signature.asc
Description: PGP signature

Reply via email to