Copy /etc/hostname and /etc/hosts into target
authorBenjamin Drung <benjamin.drung@cloud.ionos.com>
Wed, 21 Aug 2019 14:55:13 +0000 (16:55 +0200)
committerBenjamin Drung <benjamin.drung@cloud.ionos.com>
Wed, 21 Aug 2019 14:55:13 +0000 (16:55 +0200)
If the target system has an empty /etc/hostname file, copy /etc/hostname
from the initramfs into the target system. If the target system has an
empty or default /etc/hosts file, copy /etc/hosts from the initramfs
into the target system.

Signed-off-by: Benjamin Drung <benjamin.drung@cloud.ionos.com>
components/9990-main.sh

index 7e385f5..4a22909 100755 (executable)
@@ -165,6 +165,20 @@ Live ()
                fi
        fi
 
+       if [ -f /etc/hostname ] && ! grep -E -q -v '^[[:space:]]*(#|$)' "${rootmnt}/etc/hostname"
+       then
+               log_begin_msg "Copying /etc/hostname to ${rootmnt}/etc/hostname"
+               cp -v /etc/hostname "${rootmnt}/etc/hostname"
+               log_end_msg
+       fi
+
+       if [ -f /etc/hosts ] && ! grep -E -q -v '^[[:space:]]*(#|$|(127.0.0.1|::1|ff02::[12])[[:space:]])' "${rootmnt}/etc/hosts"
+       then
+               log_begin_msg "Copying /etc/hosts to ${rootmnt}/etc/hosts"
+               cp -v /etc/hosts "${rootmnt}/etc/hosts"
+               log_end_msg
+       fi
+
        if [ -L /root/etc/resolv.conf ] ; then
                # assume we have resolvconf
                DNSFILE="${rootmnt}/etc/resolvconf/resolv.conf.d/base"