]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/06dbus-daemon/module-setup.sh
fix: shellcheck 0.7.2
[thirdparty/dracut.git] / modules.d / 06dbus-daemon / module-setup.sh
1 #!/bin/bash
2 # This file is part of dracut.
3 # SPDX-License-Identifier: GPL-2.0-or-later
4
5 # Prerequisite check(s) for module.
6 check() {
7
8 # If the binary(s) requirements are not fulfilled the module can't be installed
9 require_binaries busctl || return 1
10 require_binaries dbus-daemon || return 1
11 require_binaries dbus-send || return 1
12
13 # Return 255 to only include the module, if another module requires it.
14 return 255
15 }
16
17 # Module dependency requirements.
18 depends() {
19
20 # This module has external dependency on the systemd module.
21 echo systemd
22 # Return 0 to include the dependent systemd module in the initramfs.
23 return 0
24 }
25
26 # Install the required file(s) and directories for the module in the initramfs.
27 install() {
28 # dbus conflicts with dbus-broker.
29 if dracut_module_included "dbus-broker"; then
30 derror "dbus conflicts with dbus-broker in the initramfs."
31 return 1
32 fi
33
34 # Create dbus related directories.
35 inst_dir "$dbus"
36 inst_dir "$dbusinterfaces"
37 inst_dir "$dbusservices"
38 inst_dir "$dbussession"
39 inst_dir "$dbussystem"
40 inst_dir "$dbussystemservices"
41 inst_dir "$dbusconfdir"
42 inst_dir "$dbusinterfacesconfdir"
43 inst_dir "$dbusservicesconfdir"
44 inst_dir "$dbussessionconfdir"
45 inst_dir "$dbussystemconfdir"
46 inst_dir "$dbussystemservicesconfdir"
47
48 inst_multiple -o \
49 "$dbus"/system.conf \
50 "$dbussystem"/org.freedesktop.systemd1.conf \
51 "$dbusservicesconfdir"/org.freedesktop.systemd1.service \
52 "$dbussystemservices"/org.freedesktop.systemd1.service \
53 "$systemdsystemunitdir"/dbus.service \
54 "$systemdsystemunitdir"/dbus.socket \
55 "$systemdsystemunitdir"/dbus.target.wants \
56 busctl dbus-send dbus-daemon
57
58 # Adjusting dependencies for initramfs in the dbus service unit.
59 # shellcheck disable=SC1004
60 sed -i -e \
61 '/^\[Unit\]/aDefaultDependencies=no\
62 Conflicts=shutdown.target\
63 Before=shutdown.target' \
64 "$initdir$systemdsystemunitdir/dbus.service"
65
66 # Adjusting dependencies for initramfs in the dbus socket unit.
67 # shellcheck disable=SC1004
68 sed -i -e \
69 '/^\[Unit\]/aDefaultDependencies=no\
70 Conflicts=shutdown.target\
71 Before=shutdown.target
72 /^\[Socket\]/aRemoveOnStop=yes' \
73 "$initdir$systemdsystemunitdir/dbus.socket"
74
75 # Adding the user and group for dbus
76 grep '^\(d\|message\)bus:' "$dracutsysrootdir"/etc/passwd >> "$initdir/etc/passwd"
77 grep '^\(d\|message\)bus:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"
78
79 # Install the hosts local user configurations if enabled.
80 if [[ $hostonly ]]; then
81 inst_multiple -H -o \
82 "$dbusconfdir"/system.conf \
83 "$systemdsystemconfdir"/dbus.socket \
84 "$systemdsystemconfdir"/dbus.socket.d/*.conf \
85 "$systemdsystemconfdir"/dbus.service \
86 "$systemdsystemconfdir"/dbus.service.d/*.conf
87 fi
88
89 # We need to make sure that systemd-tmpfiles-setup.service->dbus.socket
90 # will not wait for local-fs.target to start if swap is encrypted,
91 # this would make dbus wait the timeout for the swap before loading.
92 # This could delay sysinit services that are dependent on dbus.service.
93 sed -i -Ee \
94 '/^After/s/(After[[:space:]]*=.*)(local-fs.target[[:space:]]*)(.*)/\1-\.mount \3/' \
95 "$initdir$systemdsystemunitdir/systemd-tmpfiles-setup.service"
96 }