From d54f811220cbc9bf5432ceab12d1b1c514981e6a Mon Sep 17 00:00:00 2001 From: Thorsten Bruhns Date: Sun, 12 Nov 2023 17:39:15 +0100 Subject: [PATCH] rhel: Check for networking-scripts before removal (#1532) --- packer_templates/scripts/rhel/cleanup_dnf.sh | 14 ++++++++------ packer_templates/scripts/rhel/cleanup_yum.sh | 13 +++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packer_templates/scripts/rhel/cleanup_dnf.sh b/packer_templates/scripts/rhel/cleanup_dnf.sh index 2fa9737d8..7f8ddd206 100644 --- a/packer_templates/scripts/rhel/cleanup_dnf.sh +++ b/packer_templates/scripts/rhel/cleanup_dnf.sh @@ -31,12 +31,14 @@ mkdir -p /etc/udev/rules.d/70-persistent-net.rules; rm -f /lib/udev/rules.d/75-persistent-net-generator.rules; rm -rf /dev/.udev/; -for ndev in /etc/sysconfig/network-scripts/ifcfg-*; do - if [ "$(basename "$ndev")" != "ifcfg-lo" ]; then - sed -i '/^HWADDR/d' "$ndev"; - sed -i '/^UUID/d' "$ndev"; - fi -done +if test -f /etc/sysconfig/network-scripts/ifcfg-*; then + for ndev in /etc/sysconfig/network-scripts/ifcfg-*; do + if [ "$(basename "$ndev")" != "ifcfg-lo" ]; then + sed -i '/^HWADDR/d' "$ndev"; + sed -i '/^UUID/d' "$ndev"; + fi + done +fi echo "truncate any logs that have built up during the install" find /var/log -type f -exec truncate --size=0 {} \; diff --git a/packer_templates/scripts/rhel/cleanup_yum.sh b/packer_templates/scripts/rhel/cleanup_yum.sh index 6dd7cf34e..077319234 100644 --- a/packer_templates/scripts/rhel/cleanup_yum.sh +++ b/packer_templates/scripts/rhel/cleanup_yum.sh @@ -31,13 +31,14 @@ mkdir -p /etc/udev/rules.d/70-persistent-net.rules; rm -f /lib/udev/rules.d/75-persistent-net-generator.rules; rm -rf /dev/.udev/; -for ndev in /etc/sysconfig/network-scripts/ifcfg-*; do - if [ "$(basename "$ndev")" != "ifcfg-lo" ]; then - sed -i '/^HWADDR/d' "$ndev"; - sed -i '/^UUID/d' "$ndev"; - fi -done +if test -f /etc/sysconfig/network-scripts/ifcfg-*; then + for ndev in /etc/sysconfig/network-scripts/ifcfg-*; do + if [ "$(basename "$ndev")" != "ifcfg-lo" ]; then + sed -i '/^UUID/d' "$ndev"; + fi + done +fi echo "truncate any logs that have built up during the install" find /var/log -type f -exec truncate --size=0 {} \;