Skip to content

Commit

Permalink
feat(connman): introduce connman support module
Browse files Browse the repository at this point in the history
Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
  • Loading branch information
zboszor authored and johannbg committed Mar 28, 2022
1 parent 42e9d18 commit f30d035
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 1 deletion.
24 changes: 24 additions & 0 deletions modules.d/35connman/cm-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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
24 changes: 24 additions & 0 deletions modules.d/35connman/cm-initrd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[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
12 changes: 12 additions & 0 deletions modules.d/35connman/cm-lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/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
}
15 changes: 15 additions & 0 deletions modules.d/35connman/cm-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/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
16 changes: 16 additions & 0 deletions modules.d/35connman/cm-wait-online-initrd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[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
46 changes: 46 additions & 0 deletions modules.d/35connman/module-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/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"
}
4 changes: 3 additions & 1 deletion modules.d/40network/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ check() {
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
Expand All @@ -19,6 +19,8 @@ depends() {
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
Expand Down

0 comments on commit f30d035

Please sign in to comment.