-
Notifications
You must be signed in to change notification settings - Fork 56
/
initramfs-suspend
56 lines (44 loc) · 1.75 KB
/
initramfs-suspend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# Copyright 2013 Vianney le Clément de Saint-Marcq <[email protected]>
# Copyright 2017 Zhongfu Li <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with This program. If not, see http://www.gnu.org/licenses/.
cryptname="${1}"
YUBIKEY_LUKS_SLOT=2 #Set this in case the value is missing in /etc/ykluks.cfg
# Start udev from initramfs
/lib/systemd/systemd-udevd --daemon --resolve-names=never
# Sync one more time, just in case
sync
# Suspend root device
[ -z "${cryptname}" ] || cryptsetup luksSuspend "${cryptname}"
# Suspend the system
echo mem > /sys/power/state
# Resume root device
. /etc/ykluks.cfg
[ -z "${cryptname}" ] ||
while true; do
P1=$(/lib/cryptsetup/askpass "$WELCOME_TEXT")
if [ "$HASH" = "1" ]; then
P1=$(printf %s "$P1" | sha256sum | awk '{print $1}')
fi
R="$(printf %s "$P1" | ykchalresp -"$YUBIKEY_LUKS_SLOT" -i- 2>/dev/null || true)"
if [ "$CONCATENATE" = "1" ]; then
printf %s "$P1$R" | cryptsetup luksResume "${cryptname}" 2>&1;
else
printf %s "$R" | cryptsetup luksResume "${cryptname}" 2>&1;
fi
[ $? -le 1 ] && break
sleep 2
done
# Stop udev from initramfs, as the real daemon from rootfs will be restarted
udevadm control --exit