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