3b5284
From 3067edf07449e1dbc2dae0776da9426274b34cba Mon Sep 17 00:00:00 2001
3b5284
From: Beniamino Galvani <bgalvani@redhat.com>
3b5284
Date: Wed, 24 Jun 2020 13:06:05 +0200
3b5284
Subject: [PATCH] network-manager: move connection generation to a lib file
3b5284
3b5284
Move the connection generation code to a library file so that it can
3b5284
be reused from other places.
3b5284
3b5284
(cherry picked from commit 6e1e87cd2567801b10b2b4f716436c48688408bf)
3b5284
3b5284
Resolves: #1847518
3b5284
---
3b5284
 modules.d/35network-manager/module-setup.sh |  1 +
3b5284
 modules.d/35network-manager/nm-config.sh    | 15 +++------------
3b5284
 modules.d/35network-manager/nm-lib.sh       | 20 ++++++++++++++++++++
3b5284
 3 files changed, 24 insertions(+), 12 deletions(-)
3b5284
3b5284
diff --git a/modules.d/35network-manager/module-setup.sh b/modules.d/35network-manager/module-setup.sh
3b5284
index ad2a1534..ed2f399e 100755
3b5284
--- a/modules.d/35network-manager/module-setup.sh
3b5284
+++ b/modules.d/35network-manager/module-setup.sh
3b5284
@@ -37,6 +37,7 @@ install() {
3b5284
     inst_hook initqueue/settled 99 "$moddir/nm-run.sh"
3b5284
     inst_rules 85-nm-unmanaged.rules
3b5284
     inst_libdir_file "NetworkManager/$_nm_version/libnm-device-plugin-team.so"
3b5284
+    inst_simple "$moddir/nm-lib.sh" "/lib/nm-lib.sh"
3b5284
 
3b5284
     if [[ -x "$initdir/usr/sbin/dhclient" ]]; then
3b5284
         inst /usr/libexec/nm-dhcp-helper
3b5284
diff --git a/modules.d/35network-manager/nm-config.sh b/modules.d/35network-manager/nm-config.sh
3b5284
index 39a1c8bd..2b9df020 100755
3b5284
--- a/modules.d/35network-manager/nm-config.sh
3b5284
+++ b/modules.d/35network-manager/nm-config.sh
3b5284
@@ -1,18 +1,9 @@
3b5284
 #!/bin/sh
3b5284
 
3b5284
+type nm_generate_connections >/dev/null 2>&1 || . /lib/nm-lib.sh
3b5284
+
3b5284
 if [ -n "$netroot" ] || [ -e /tmp/net.ifaces ]; then
3b5284
     echo rd.neednet >> /etc/cmdline.d/35-neednet.conf
3b5284
 fi
3b5284
 
3b5284
-/usr/libexec/nm-initrd-generator -- $(getcmdline)
3b5284
-
3b5284
-if getargbool 0 rd.neednet; then
3b5284
-  for i in /usr/lib/NetworkManager/system-connections/* \
3b5284
-           /run/NetworkManager/system-connections/* \
3b5284
-           /etc/NetworkManager/system-connections/* \
3b5284
-           /etc/sysconfig/network-scripts/ifcfg-*; do
3b5284
-    [ -f "$i" ] || continue
3b5284
-    echo '[ -f /tmp/nm.done ]' >$hookdir/initqueue/finished/nm.sh
3b5284
-    break
3b5284
-  done
3b5284
-fi
3b5284
+nm_generate_connections
3b5284
diff --git a/modules.d/35network-manager/nm-lib.sh b/modules.d/35network-manager/nm-lib.sh
3b5284
new file mode 100644
3b5284
index 00000000..fe053cfa
3b5284
--- /dev/null
3b5284
+++ b/modules.d/35network-manager/nm-lib.sh
3b5284
@@ -0,0 +1,20 @@
3b5284
+#!/bin/bash
3b5284
+
3b5284
+type getcmdline >/dev/null 2>&1 || . /lib/dracut-lib.sh
3b5284
+
3b5284
+nm_generate_connections()
3b5284
+{
3b5284
+    rm -f /run/NetworkManager/system-connections/*
3b5284
+    /usr/libexec/nm-initrd-generator -- $(getcmdline)
3b5284
+
3b5284
+    if getargbool 0 rd.neednet; then
3b5284
+        for i in /usr/lib/NetworkManager/system-connections/* \
3b5284
+                 /run/NetworkManager/system-connections/* \
3b5284
+                 /etc/NetworkManager/system-connections/* \
3b5284
+                 /etc/sysconfig/network-scripts/ifcfg-*; do
3b5284
+            [ -f "$i" ] || continue
3b5284
+            echo '[ -f /tmp/nm.done ]' >$hookdir/initqueue/finished/nm.sh
3b5284
+            break
3b5284
+        done
3b5284
+    fi
3b5284
+}
3b5284