--- /dev/null
+#!/bin/sh
+
+type cm_generate_connections > /dev/null 2>&1 || . /lib/cm-lib.sh
+
+if [ -n "$netroot" ] || [ -e /tmp/net.ifaces ]; then
+ echo rd.neednet >> /etc/cmdline.d/connman.conf
+fi
+
+if getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then
+ if [ -n "$DRACUT_SYSTEMD" ]; then
+ # Enable tty output if a usable console is found
+ # shellcheck disable=SC2217
+ if [ -w /dev/console ] && (echo < /dev/console) > /dev/null 2> /dev/null; then
+ mkdir -p /run/systemd/system/cm-initrd.service.d
+ cat << EOF > /run/systemd/system/cm-initrd.service.d/tty-output.conf
+[Service]
+StandardOutput=tty
+EOF
+ systemctl --no-block daemon-reload
+ fi
+ fi
+fi
+
+cm_generate_connections
--- /dev/null
+[Unit]
+DefaultDependencies=no
+Wants=systemd-udev-trigger.service
+After=systemd-udev-trigger.service
+After=dracut-cmdline.service
+Wants=network.target
+Before=network.target
+RequiresMountsFor=/var/lib/connman
+After=dbus.service
+ConditionPathExists=/run/connman/initrd/neednet
+
+[Service]
+Type=dbus
+BusName=net.connman
+Restart=on-failure
+ExecStart=/usr/sbin/connmand -n
+StandardOutput=null
+CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_ADMIN
+ProtectHome=true
+ProtectSystem=full
+
+[Install]
+WantedBy=initrd.target
+Also=cm-wait-online-initrd.service
--- /dev/null
+#!/bin/sh
+
+type getcmdline > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+cm_generate_connections() {
+ if getargbool 0 rd.neednet; then
+ mkdir -p "$hookdir"/initqueue/finished
+ echo '[ -f /tmp/cm.done ]' > "$hookdir"/initqueue/finished/cm.sh
+ mkdir -p /run/connman/initrd
+ : > /run/connman/initrd/neednet # activate ConnMan services
+ fi
+}
--- /dev/null
+#!/bin/bash
+
+type source_hook > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+if [ -e /tmp/cm.done ]; then
+ return
+fi
+
+while read -r _serv; do
+ ifname=$(connmanctl services "$_serv" | grep Interface= | sed 's/^.*Interface=\([^,]*\).*$/\1/')
+ source_hook initqueue/online "$ifname"
+ /sbin/netroot "$ifname"
+done < <(connmanctl services | grep -oE '[^ ]+$')
+
+: > /tmp/cm.done
--- /dev/null
+[Unit]
+DefaultDependencies=no
+Requires=cm-initrd.service
+After=cm-initrd.service
+Before=network-online.target
+Before=dracut-initqueue.service
+ConditionPathExists=/run/connman/initrd/neednet
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/connmand-wait-online
+RemainAfterExit=yes
+
+[Install]
+WantedBy=initrd.target
+WantedBy=network-online.target
--- /dev/null
+#!/bin/bash
+
+# called by dracut
+check() {
+ require_binaries sed grep connmand connmanctl connmand-wait-online || return 1
+
+ # do not add this module by default
+ return 255
+}
+
+# called by dracut
+depends() {
+ echo dbus systemd bash
+ return 0
+}
+
+# called by dracut
+installkernel() {
+ return 0
+}
+
+# called by dracut
+install() {
+ # We don't need `ip` but having it is *really* useful for people debugging
+ # in an emergency shell.
+ inst_multiple ip sed grep
+
+ inst connmand
+ inst connmanctl
+ inst connmand-wait-online
+ inst "$dbussystem"/connman.conf
+ [[ $hostonly ]] && [[ -f $dracutsysrootdir/etc/connman/main.conf ]] && inst /etc/connman/main.conf
+ inst_dir /usr/lib/connman/plugins
+ inst_dir /var/lib/connman
+
+ inst_hook cmdline 99 "$moddir/cm-config.sh"
+
+ inst_simple "$moddir"/cm-initrd.service "$systemdsystemunitdir"/cm-initrd.service
+ inst_simple "$moddir"/cm-wait-online-initrd.service "$systemdsystemunitdir"/cm-wait-online-initrd.service
+
+ $SYSTEMCTL -q --root "$initdir" enable cm-initrd.service
+
+ inst_hook initqueue/settled 99 "$moddir/cm-run.sh"
+
+ inst_simple "$moddir/cm-lib.sh" "/lib/cm-lib.sh"
+}
depends() {
is_qemu_virtualized && echo -n "qemu-net "
- for module in network-wicked network-manager network-legacy systemd-networkd; do
+ for module in network-wicked connman network-manager network-legacy systemd-networkd; do
if dracut_module_included "$module"; then
network_handler="$module"
break
if [ -z "$network_handler" ]; then
if [[ -e $dracutsysrootdir$systemdsystemunitdir/wicked.service ]]; then
network_handler="network-wicked"
+ elif [[ -e $dracutsysrootdir$systemdsystemunitdir/connman.service ]]; then
+ network_handler="connman"
elif [[ -x $dracutsysrootdir/usr/libexec/nm-initrd-generator ]] || [[ -x $dracutsysrootdir/usr/lib/nm-initrd-generator ]]; then
network_handler="network-manager"
elif [[ -x $dracutsysrootdir$systemdutildir/systemd-networkd ]]; then