Fix up multiple match clauses generated by borked cloud-init

This commit is contained in:
Laura Hausmann 2023-03-13 04:11:53 +01:00
parent e51c9bc31e
commit 649e54c9a0
Signed by untrusted user: zotan
GPG key ID: D044E84C5BE01605

View file

@ -314,6 +314,17 @@ basic_postinstall(){
if [[ -n $cinetwork ]]; then
cp /etc/systemd/network/??-cloud-init-*.link /etc/systemd/network/??-cloud-init-*.network /mnt/etc/systemd/network || : # ignore failures because file doesn't exist
cat /mnt/etc/systemd/network/??-cloud-init-*.network | grep -E 'DNS|Domains' | sed 's/DNS=/nameserver /g' | sed 's/Domains=/search /g' >> /mnt/etc/resolv.conf
# Fix up multiple match clauses generated by borked cloud-init
for f in /mnt/etc/systemd/network/??-cloud-init-*.network; do
# Check if [Match] section contains MACAddress
cat "$f" | grep "\[Match\]" --after-context 999 | sed -z 's/\n\n/.*/\n/g' | grep -q "MACAddress="
if [[ $? -eq 0 ]]; then
# Remove Name= match clause
sed -z -i 's/Name=.*\n//g' "$f"
fi
done
archchroot "systemctl enable systemd-networkd"
fi
}