Skip to content

Commit f30d035

Browse files
zboszorjohannbg
authored andcommitted
feat(connman): introduce connman support module
Signed-off-by: Zoltán Böszörményi <[email protected]>
1 parent 42e9d18 commit f30d035

File tree

7 files changed

+140
-1
lines changed

7 files changed

+140
-1
lines changed

modules.d/35connman/cm-config.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
type cm_generate_connections > /dev/null 2>&1 || . /lib/cm-lib.sh
4+
5+
if [ -n "$netroot" ] || [ -e /tmp/net.ifaces ]; then
6+
echo rd.neednet >> /etc/cmdline.d/connman.conf
7+
fi
8+
9+
if getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then
10+
if [ -n "$DRACUT_SYSTEMD" ]; then
11+
# Enable tty output if a usable console is found
12+
# shellcheck disable=SC2217
13+
if [ -w /dev/console ] && (echo < /dev/console) > /dev/null 2> /dev/null; then
14+
mkdir -p /run/systemd/system/cm-initrd.service.d
15+
cat << EOF > /run/systemd/system/cm-initrd.service.d/tty-output.conf
16+
[Service]
17+
StandardOutput=tty
18+
EOF
19+
systemctl --no-block daemon-reload
20+
fi
21+
fi
22+
fi
23+
24+
cm_generate_connections
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[Unit]
2+
DefaultDependencies=no
3+
Wants=systemd-udev-trigger.service
4+
After=systemd-udev-trigger.service
5+
After=dracut-cmdline.service
6+
Wants=network.target
7+
Before=network.target
8+
RequiresMountsFor=/var/lib/connman
9+
After=dbus.service
10+
ConditionPathExists=/run/connman/initrd/neednet
11+
12+
[Service]
13+
Type=dbus
14+
BusName=net.connman
15+
Restart=on-failure
16+
ExecStart=/usr/sbin/connmand -n
17+
StandardOutput=null
18+
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_ADMIN
19+
ProtectHome=true
20+
ProtectSystem=full
21+
22+
[Install]
23+
WantedBy=initrd.target
24+
Also=cm-wait-online-initrd.service

modules.d/35connman/cm-lib.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
type getcmdline > /dev/null 2>&1 || . /lib/dracut-lib.sh
4+
5+
cm_generate_connections() {
6+
if getargbool 0 rd.neednet; then
7+
mkdir -p "$hookdir"/initqueue/finished
8+
echo '[ -f /tmp/cm.done ]' > "$hookdir"/initqueue/finished/cm.sh
9+
mkdir -p /run/connman/initrd
10+
: > /run/connman/initrd/neednet # activate ConnMan services
11+
fi
12+
}

modules.d/35connman/cm-run.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
type source_hook > /dev/null 2>&1 || . /lib/dracut-lib.sh
4+
5+
if [ -e /tmp/cm.done ]; then
6+
return
7+
fi
8+
9+
while read -r _serv; do
10+
ifname=$(connmanctl services "$_serv" | grep Interface= | sed 's/^.*Interface=\([^,]*\).*$/\1/')
11+
source_hook initqueue/online "$ifname"
12+
/sbin/netroot "$ifname"
13+
done < <(connmanctl services | grep -oE '[^ ]+$')
14+
15+
: > /tmp/cm.done
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
DefaultDependencies=no
3+
Requires=cm-initrd.service
4+
After=cm-initrd.service
5+
Before=network-online.target
6+
Before=dracut-initqueue.service
7+
ConditionPathExists=/run/connman/initrd/neednet
8+
9+
[Service]
10+
Type=oneshot
11+
ExecStart=/usr/sbin/connmand-wait-online
12+
RemainAfterExit=yes
13+
14+
[Install]
15+
WantedBy=initrd.target
16+
WantedBy=network-online.target
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# called by dracut
4+
check() {
5+
require_binaries sed grep connmand connmanctl connmand-wait-online || return 1
6+
7+
# do not add this module by default
8+
return 255
9+
}
10+
11+
# called by dracut
12+
depends() {
13+
echo dbus systemd bash
14+
return 0
15+
}
16+
17+
# called by dracut
18+
installkernel() {
19+
return 0
20+
}
21+
22+
# called by dracut
23+
install() {
24+
# We don't need `ip` but having it is *really* useful for people debugging
25+
# in an emergency shell.
26+
inst_multiple ip sed grep
27+
28+
inst connmand
29+
inst connmanctl
30+
inst connmand-wait-online
31+
inst "$dbussystem"/connman.conf
32+
[[ $hostonly ]] && [[ -f $dracutsysrootdir/etc/connman/main.conf ]] && inst /etc/connman/main.conf
33+
inst_dir /usr/lib/connman/plugins
34+
inst_dir /var/lib/connman
35+
36+
inst_hook cmdline 99 "$moddir/cm-config.sh"
37+
38+
inst_simple "$moddir"/cm-initrd.service "$systemdsystemunitdir"/cm-initrd.service
39+
inst_simple "$moddir"/cm-wait-online-initrd.service "$systemdsystemunitdir"/cm-wait-online-initrd.service
40+
41+
$SYSTEMCTL -q --root "$initdir" enable cm-initrd.service
42+
43+
inst_hook initqueue/settled 99 "$moddir/cm-run.sh"
44+
45+
inst_simple "$moddir/cm-lib.sh" "/lib/cm-lib.sh"
46+
}

modules.d/40network/module-setup.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ check() {
99
depends() {
1010
is_qemu_virtualized && echo -n "qemu-net "
1111

12-
for module in network-wicked network-manager network-legacy systemd-networkd; do
12+
for module in network-wicked connman network-manager network-legacy systemd-networkd; do
1313
if dracut_module_included "$module"; then
1414
network_handler="$module"
1515
break
@@ -19,6 +19,8 @@ depends() {
1919
if [ -z "$network_handler" ]; then
2020
if [[ -e $dracutsysrootdir$systemdsystemunitdir/wicked.service ]]; then
2121
network_handler="network-wicked"
22+
elif [[ -e $dracutsysrootdir$systemdsystemunitdir/connman.service ]]; then
23+
network_handler="connman"
2224
elif [[ -x $dracutsysrootdir/usr/libexec/nm-initrd-generator ]] || [[ -x $dracutsysrootdir/usr/lib/nm-initrd-generator ]]; then
2325
network_handler="network-manager"
2426
elif [[ -x $dracutsysrootdir$systemdutildir/systemd-networkd ]]; then

0 commit comments

Comments
 (0)