]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
network-manager: add module
authorLubomir Rintel <lkundrak@v3.sk>
Thu, 30 Aug 2018 14:44:22 +0000 (16:44 +0200)
committerHarald Hoyer <harald@redhat.com>
Fri, 21 Sep 2018 09:32:01 +0000 (11:32 +0200)
dracut.spec
modules.d/35network-manager/module-setup.sh [new file with mode: 0755]
modules.d/35network-manager/nm-config.sh [new file with mode: 0755]
modules.d/35network-manager/nm-run.sh [new file with mode: 0755]
modules.d/40network/module-setup.sh

index f6486d50e38611865963b6a9b6823a438a53485c..b609982471dd598d323c7d847d0358191ec69c10 100644 (file)
@@ -419,6 +419,7 @@ install -m 0755 51-dracut-rescue-postinst.sh $RPM_BUILD_ROOT%{_sysconfdir}/kerne
 
 %files network
 %{dracutlibdir}/modules.d/02systemd-networkd
+%{dracutlibdir}/modules.d/35network-manager
 %{dracutlibdir}/modules.d/35network-legacy
 %{dracutlibdir}/modules.d/40network
 %{dracutlibdir}/modules.d/45ifcfg
diff --git a/modules.d/35network-manager/module-setup.sh b/modules.d/35network-manager/module-setup.sh
new file mode 100755 (executable)
index 0000000..62aba3c
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+# called by dracut
+check() {
+    local _program
+
+    require_binaries sed grep || return 1
+
+    # do not add this module by default
+    return 255
+}
+
+# called by dracut
+depends() {
+    return 0
+}
+
+# called by dracut
+installkernel() {
+    return 0
+}
+
+# called by dracut
+install() {
+    local _nm_version
+
+    _nm_version=$(NetworkManager --version)
+
+    inst_multiple sed grep
+
+    inst NetworkManager
+    inst /usr/libexec/nm-initrd-generator
+    inst_multiple -o teamd dhclient
+    inst_hook cmdline 99 "$moddir/nm-config.sh"
+    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"
+
+    if [[ -x "$initdir/usr/sbin/dhclient" ]]; then
+        inst /usr/libexec/nm-dhcp-helper
+    elif ! [[ -e "$initdir/etc/machine-id" ]]; then
+        # The internal DHCP client silently fails if we
+        # have no machine-id
+        systemd-machine-id-setup --root="$initdir"
+    fi
+
+    # We don't install the ifcfg files from the host automatically.
+    # But if the user chooses to include them, we pull in the machinery to read them.
+    if ! [[ -d "$initdir/etc/sysconfig/network-scripts" ]]; then
+        inst_libdir_file "NetworkManager/$_nm_version/libnm-settings-plugin-ifcfg-rh.so"
+    fi
+}
diff --git a/modules.d/35network-manager/nm-config.sh b/modules.d/35network-manager/nm-config.sh
new file mode 100755 (executable)
index 0000000..1339ebe
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+/usr/libexec/nm-initrd-generator -- $(getcmdline)
diff --git a/modules.d/35network-manager/nm-run.sh b/modules.d/35network-manager/nm-run.sh
new file mode 100755 (executable)
index 0000000..f6defa9
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+if getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then
+    /usr/sbin/NetworkManager --configure-and-quit=initrd --debug --log-level=trace
+else
+    /usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon
+fi
+
+for _i in /sys/class/net/*/
+do
+    state=/run/NetworkManager/devices/$(cat $_i/ifindex)
+    grep -q managed=true $state 2>/dev/null || continue
+    ifname=$(basename $_i)
+    sed -n 's/root-path/new_root_path/p' <$state >/tmp/dhclient.$ifname.dhcpopts
+    /sbin/netroot $ifname
+done
index fbd43925e806aafd0390ff0f895e240bcb1f79ce..57c0a45e66c463351f700d97e0fb7b35066ba513 100755 (executable)
@@ -2,7 +2,12 @@
 
 # called by dracut
 depends() {
-    echo "network-legacy"
+    echo -n "kernel-network-modules "
+    if ! dracut_module_included "network-legacy" && [ -x "/usr/libexec/nm-initrd-generator" ] ; then
+        echo "network-manager"
+    else
+        echo "network-legacy"
+    fi
     return 0
 }