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