From 11a34f6b55f91610effd79ff1bf6a4bb2db760d3 Mon Sep 17 00:00:00 2001
From: Laszlo Gombos <laszlo.gombos@gmail.com>
Date: Wed, 18 Jan 2023 19:59:24 +0000
Subject: [PATCH] meta module should check if module exists

Bug: https://github.com/dracutdevs/dracut/issues/1756
---
 modules.d/40network/module-setup.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/modules.d/40network/module-setup.sh b/modules.d/40network/module-setup.sh
index 1ab13ef..078cb4b 100755
--- a/modules.d/40network/module-setup.sh
+++ b/modules.d/40network/module-setup.sh
@@ -17,15 +17,15 @@ depends() {
     done

     if [ -z "$network_handler" ]; then
-        if [[ -e $dracutsysrootdir$systemdsystemunitdir/wicked.service ]]; then
+        if [[ -d "$dracutbasedir"/modules.d/35network-wicked ]]  && [[ -e $dracutsysrootdir$systemdsystemunitdir/wicked.service ]]; then
             network_handler="network-wicked"
-        elif [[ -e $dracutsysrootdir$systemdsystemunitdir/connman.service ]]; then
+        elif [[ -d "$dracutbasedir"/modules.d/35connman ]]  && [[ -e $dracutsysrootdir$systemdsystemunitdir/connman.service ]]; then
             network_handler="connman"
-        elif [[ -x $dracutsysrootdir/usr/libexec/nm-initrd-generator ]] || [[ -x $dracutsysrootdir/usr/lib/nm-initrd-generator ]]; then
+        elif [[ -d "$dracutbasedir"/modules.d/35network-manager ]]  && ( [[ -x $dracutsysrootdir/usr/libexec/nm-initrd-generator ]] || [[ -x $dracutsysrootdir/usr/lib/nm-initrd-generator ]] ); then
             network_handler="network-manager"
-        elif [[ -x $dracutsysrootdir$systemdutildir/systemd-networkd ]]; then
+        elif [[ -d "$dracutbasedir"/modules.d/01systemd-networkd ]] && [[ -x $dracutsysrootdir$systemdutildir/systemd-networkd ]]; then
             network_handler="systemd-networkd"
-        else
+        elif [[ -d "$dracutbasedir"/modules.d/35network-legacy ]]; then
             network_handler="network-legacy"
         fi
     fi
--
2.34.1
