]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95resume/module-setup.sh
6ddc7259b623d571eaf43724392a2f3fce72d444
[thirdparty/dracut.git] / modules.d / 95resume / module-setup.sh
1 #!/bin/bash
2
3 # called by dracut
4 check() {
5 # No point trying to support resume, if no swap partition exist
6 [[ $hostonly ]] || [[ $mount_needs ]] && {
7 for fs in "${host_fs_types[@]}"; do
8 [[ $fs =~ ^(swap|swsuspend|swsupend)$ ]] && return 0
9 done
10 return 255
11 }
12
13 return 0
14 }
15
16 # called by dracut
17 cmdline() {
18 local _resume
19
20 for dev in "${!host_fs_types[@]}"; do
21 [[ ${host_fs_types[$dev]} =~ ^(swap|swsuspend|swsupend)$ ]] || continue
22 _resume=$(shorten_persistent_dev "$(get_persistent_dev "$dev")")
23 [[ -n ${_resume} ]] && printf " resume=%s" "${_resume}"
24 done
25 }
26
27 # called by dracut
28 install() {
29 local _bin
30
31 if [[ $hostonly_cmdline == "yes" ]]; then
32 local _resumeconf=$(cmdline)
33 [[ $_resumeconf ]] && printf "%s\n" "$_resumeconf" >> "${initdir}/etc/cmdline.d/95resume.conf"
34 fi
35
36 # if systemd is included and has the hibernate-resume tool, use it and nothing else
37 if dracut_module_included "systemd" && [[ -x $dracutsysrootdir$systemdutildir/systemd-hibernate-resume ]]; then
38 inst_multiple -o \
39 $systemdutildir/system-generators/systemd-hibernate-resume-generator \
40 $systemdsystemunitdir/systemd-hibernate-resume@.service \
41 $systemdutildir/systemd-hibernate-resume
42 return 0
43 fi
44
45 # Optional uswsusp support
46 for _bin in /usr/sbin/resume /usr/lib/suspend/resume /usr/lib/uswsusp/resume
47 do
48 [[ -x "$dracutsysrootdir${_bin}" ]] && {
49 inst "${_bin}" /usr/sbin/resume
50 [[ $hostonly ]] && [[ -f $dracutsysrootdir/etc/suspend.conf ]] && inst -H /etc/suspend.conf
51 break
52 }
53 done
54
55 if ! dracut_module_included "systemd"; then
56 inst_hook cmdline 10 "$moddir/parse-resume.sh"
57 else
58 inst_script "$moddir/parse-resume.sh" /lib/dracut/parse-resume.sh
59 fi
60
61 inst_script "$moddir/resume.sh" /lib/dracut/resume.sh
62 }
63