From 316a2ea74871313473a7531f54f820f138686237 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 3 Apr 2019 18:38:37 +0200 Subject: [PATCH] Chroot: Generate interfaces network config --- debian/chroot.install | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/debian/chroot.install b/debian/chroot.install index 9d57827..04744c7 100755 --- a/debian/chroot.install +++ b/debian/chroot.install @@ -198,6 +198,28 @@ grep "/var/tmp" /target/etc/fstab || echo "/tmp /var/tmp no ### Remove all occurrences to /target sed -i 's;/target;;g' /target/etc/fstab +## }}} +## Network {{{ +net_device=$(ip r | grep "^default" | head -1 | cut -d" " -f5) +net_address=$(ip r | grep -vE "(^default|metric)" | grep "${net_device}.*src" | head -1 | awk -F" " '{print $NF}') +net_netmask=$(ipcalc "${net_address}" | awk '/Netmask:/{print $2;}') +net_broadcast=$(ip a s dev "${net_device}" | awk '/inet.*brd/{print $4}') +net_network=$(ip r | grep -vE "(^default|metric)" | grep "src ${net_address}" | head -1 | cut -d"/" -f1) +net_gateway=$(ip r | grep "^default" | head -1 | cut -d" " -f3) + +printf '%b' "auto lo +iface lo inet loopback + +auto ${net_device} +iface ${net_device} inet static + address ${net_address} + netmask ${net_netmask} + network ${net_network} + broadcast ${net_broadcast} + gateway ${net_gateway} + +source-directory /etc/network/interfaces.d" > /target/etc/network/interfaces + ## }}} # }}} # Finish {{{