a610d4285693e58b226abd8c0666544e046dc9fb
[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
7 dev=$1
8 luks=$2
9
10 if [ -f /etc/crypttab ]; then
11     while read l d rest; do
12         strstr "${l##luks-}" "${luks##luks-}" && exit 0
13         strstr "$d" "${luks##luks-}" && exit 0
14     done < /etc/crypttab
15 fi
16
17 allowdiscards="-"
18
19 # parse for allow-discards
20 if strstr "$(cryptsetup --help)" "allow-discards"; then
21     if discarduuids=$(getargs "rd.luks.allow-discards"); then
22         discarduuids=$(str_replace "$discarduuids" 'luks-' '')
23         if strstr " $discarduuids " " ${luks##luks-}"; then
24             allowdiscards="allow-discards"
25         fi
26     elif getargbool 0 rd.luks.allow-discards; then
27         allowdiscards="allow-discards"
28     fi
29 fi
30
31 echo "$luks $dev - timeout=0,$allowdiscards" >> /etc/crypttab
32
33 if command -v systemctl >/dev/null; then
34     systemctl daemon-reload
35     systemctl start cryptsetup.target
36 fi
37 exit 0