From 0e700b25dc2365c54fa6c62ea8c7bef0f4e77025 Mon Sep 17 00:00:00 2001
From: Noam Angel <noama@nvidia.com>
Date: Tue, 16 Feb 2021 08:29:42 +0000
Subject: [PATCH] Check and remove existing image interface configurations

This change will remove any existing interface configurations in the image. They are not necessary
and could interrupt with deployments. In any case they should not exist if we use
dhcp-all-interfaces element.

Change-Id: I35a4b5ea6e2315de3b0d9f8353ac2b6f4b995697
---
 .../install.d/60-remove-cloud-image-interfaces    | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/diskimage_builder/elements/dhcp-all-interfaces/install.d/60-remove-cloud-image-interfaces b/diskimage_builder/elements/dhcp-all-interfaces/install.d/60-remove-cloud-image-interfaces
index 1109fccdd..b9291370f 100755
--- a/diskimage_builder/elements/dhcp-all-interfaces/install.d/60-remove-cloud-image-interfaces
+++ b/diskimage_builder/elements/dhcp-all-interfaces/install.d/60-remove-cloud-image-interfaces
@@ -6,17 +6,16 @@ fi
 set -eu
 set -o pipefail
 
-# Cloud images may hard code the eth0 interfaces so they
+# Cloud images may hard code interfaces so they
 # boot with DHCP.
 
-# Fedora
-rm -f /etc/sysconfig/network-scripts/ifcfg-eth*
+# RHEL/CentOS/Fedora
+for ifcfg in $(ls /etc/sysconfig/network-scripts/ifcfg-* | grep -v "ifcfg-lo"); do 
+    rm -f $ifcfg
+done
 
-# Ubuntu
-rm -f /etc/network/interfaces.d/eth*.cfg
-
-# Debian
-rm -f /etc/network/interfaces.d/eth*
+# Ubuntu/Debian
+rm -f /etc/network/interfaces.d/*
 
 # Gentoo
 rm -f /etc/conf.d/net*