]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
network-manager: move connection generation to a lib file
authorBeniamino Galvani <bgalvani@redhat.com>
Wed, 24 Jun 2020 11:06:05 +0000 (13:06 +0200)
committerHarald Hoyer <harald@hoyer.xyz>
Thu, 25 Jun 2020 08:58:34 +0000 (10:58 +0200)
Move the connection generation code to a library file so that it can
be reused from other places.

modules.d/35network-manager/module-setup.sh
modules.d/35network-manager/nm-config.sh
modules.d/35network-manager/nm-lib.sh [new file with mode: 0644]

index ad2a1534d4a26157c804e50194ded0e2324ad1cf..ed2f399e279eb092d5aafef32fb723399df8d230 100755 (executable)
@@ -37,6 +37,7 @@ install() {
     inst_hook initqueue/settled 99 "$moddir/nm-run.sh"
     inst_rules 85-nm-unmanaged.rules
     inst_libdir_file "NetworkManager/$_nm_version/libnm-device-plugin-team.so"
+    inst_simple "$moddir/nm-lib.sh" "/lib/nm-lib.sh"
 
     if [[ -x "$initdir/usr/sbin/dhclient" ]]; then
         inst /usr/libexec/nm-dhcp-helper
index 39a1c8bdf508fe7eac7e78050e240dd911c26a72..2b9df020057fbc302c9467076e10e2b590e45493 100755 (executable)
@@ -1,18 +1,9 @@
 #!/bin/sh
 
+type nm_generate_connections >/dev/null 2>&1 || . /lib/nm-lib.sh
+
 if [ -n "$netroot" ] || [ -e /tmp/net.ifaces ]; then
     echo rd.neednet >> /etc/cmdline.d/35-neednet.conf
 fi
 
-/usr/libexec/nm-initrd-generator -- $(getcmdline)
-
-if getargbool 0 rd.neednet; then
-  for i in /usr/lib/NetworkManager/system-connections/* \
-           /run/NetworkManager/system-connections/* \
-           /etc/NetworkManager/system-connections/* \
-           /etc/sysconfig/network-scripts/ifcfg-*; do
-    [ -f "$i" ] || continue
-    echo '[ -f /tmp/nm.done ]' >$hookdir/initqueue/finished/nm.sh
-    break
-  done
-fi
+nm_generate_connections
diff --git a/modules.d/35network-manager/nm-lib.sh b/modules.d/35network-manager/nm-lib.sh
new file mode 100644 (file)
index 0000000..fe053cf
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+type getcmdline >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+nm_generate_connections()
+{
+    rm -f /run/NetworkManager/system-connections/*
+    /usr/libexec/nm-initrd-generator -- $(getcmdline)
+
+    if getargbool 0 rd.neednet; then
+        for i in /usr/lib/NetworkManager/system-connections/* \
+                 /run/NetworkManager/system-connections/* \
+                 /etc/NetworkManager/system-connections/* \
+                 /etc/sysconfig/network-scripts/ifcfg-*; do
+            [ -f "$i" ] || continue
+            echo '[ -f /tmp/nm.done ]' >$hookdir/initqueue/finished/nm.sh
+            break
+        done
+    fi
+}