f66162d75b0ee31d2003fa209839bba37c1c322f
[platform/upstream/dracut.git] / modules.d / 90crypt / crypt-run-generator.sh
1 #!/bin/sh
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 . /lib/dracut-lib.sh
6 type crypttab_contains >/dev/null 2>&1 || . /lib/dracut-crypt-lib.sh
7
8 dev=$1
9 luks=$2
10
11 crypttab_contains "$luks" && exit 0
12
13 allowdiscards="-"
14
15 # parse for allow-discards
16 if strstr "$(cryptsetup --help)" "allow-discards"; then
17     if discarduuids=$(getargs "rd.luks.allow-discards"); then
18         discarduuids=$(str_replace "$discarduuids" 'luks-' '')
19         if strstr " $discarduuids " " ${luks##luks-}"; then
20             allowdiscards="allow-discards"
21         fi
22     elif getargbool 0 rd.luks.allow-discards; then
23         allowdiscards="allow-discards"
24     fi
25 fi
26
27 echo "$luks $dev - timeout=0,$allowdiscards" >> /etc/crypttab
28
29 if command -v systemctl >/dev/null; then
30     systemctl daemon-reload
31     systemctl start cryptsetup.target
32 fi
33 exit 0