3 # replaces all occurrences of 'search' in 'str' with 'replacement'
5 # str_replace str search replacement
8 # str_replace ' one two three ' ' ' '_'
15 while [ "${in##*"$s"*}" != "$in" ]; do
20 printf -- '%s' "${out}${in}"
23 # get a systemd-compatible unit name from a path
24 # (mimicks unit_name_from_path_instance())
28 if command -v systemd-escape
> /dev
/null
; then
29 systemd-escape
-p -- "$dev"
33 if [ "$dev" = "/" -o -z "$dev" ]; then
40 # shellcheck disable=SC1003
41 dev
="$(str_replace "$dev" '\' '\x5c')"
42 dev
="$(str_replace "$dev" '-' '\x2d')"
43 if [ "${dev##.}" != "$dev" ]; then
46 dev
="$(str_replace "$dev" '/' '-')"
51 # set_systemd_timeout_for_dev [-n] <dev> [<timeout>]
52 # Set 'rd.timeout' as the systemd timeout for <dev>
53 set_systemd_timeout_for_dev
() {
59 [ -z "$DRACUT_SYSTEMD" ] && return 0
61 if [ "$1" = "-n" ]; then
69 _timeout
=$
(getarg rd.timeout
)
72 _timeout
=${_timeout:-0}
74 _name
=$
(dev_unit_name
"$1")
75 if ! [ -L "${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device" ]; then
76 [ -d "${PREFIX}"/etc
/systemd
/system
/initrd.target.wants
] || mkdir
-p "${PREFIX}"/etc
/systemd
/system
/initrd.target.wants
77 ln -s ..
/"${_name}".device "${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device"
78 type mark_hostonly
> /dev
/null
2>&1 && mark_hostonly
/etc
/systemd
/system
/initrd.target.wants
/"${_name}".device
82 if ! [ -f "${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf" ]; then
83 mkdir
-p "${PREFIX}/etc/systemd/system/${_name}.device.d"
86 echo "JobTimeoutSec=$_timeout"
87 echo "JobRunningTimeoutSec=$_timeout"
88 } > "${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf"
89 type mark_hostonly
> /dev
/null
2>&1 && mark_hostonly
/etc
/systemd
/system
/"${_name}".device.d
/timeout.conf
93 if [ -z "$PREFIX" ] && [ "$_needreload" = 1 ] && [ -z "$_noreload" ]; then
94 /sbin
/initqueue
--onetime --unique --name daemon-reload systemctl daemon-reload
98 # wait_for_dev <dev> [<timeout>]
100 # Installs a initqueue-finished script,
101 # which will cause the main loop only to exit,
102 # if the device <dev> is recognized by the system.
107 if [ "$1" = "-n" ]; then
112 _name
="$(str_replace "$1" '/' '\x2f')"
114 type mark_hostonly
> /dev
/null
2>&1 && mark_hostonly
"$hookdir/initqueue/finished/devexists-${_name}.sh"
116 [ -e "${PREFIX}$hookdir/initqueue/finished/devexists-${_name}.sh" ] && return 0
118 printf '[ -e "%s" ]\n' "$1" \
119 >> "${PREFIX}$hookdir/initqueue/finished/devexists-${_name}.sh"
121 printf '[ -e "%s" ] || ' "$1"
122 printf 'warn "\"%s\" does not exist"\n' "$1"
123 } >> "${PREFIX}$hookdir/emergency/80-${_name}.sh"
125 set_systemd_timeout_for_dev
$_noreload "$@"
128 cancel_wait_for_dev
() {
130 _name
="$(str_replace "$1" '/' '\x2f')"
131 rm -f -- "$hookdir/initqueue/finished/devexists-${_name}.sh"
132 rm -f -- "$hookdir/emergency/80-${_name}.sh"
133 if [ -n "$DRACUT_SYSTEMD" ]; then
134 _name
=$
(dev_unit_name
"$1")
135 rm -f -- "${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device"
136 rm -f -- "${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf"
137 /sbin
/initqueue
--onetime --unique --name daemon-reload systemctl daemon-reload