return $ret
}
+# luks_open_interactive dev mapname [prompt] [cryptsetupopts]
+#
+# Prompt for a LUKS passphrase and open the device. Uses Plymouth if
+# available, otherwise falls back to TTY. Reads rd.luks.timeout for
+# the passphrase input timeout.
+luks_open_interactive() {
+ local dev="$1" mapname="$2"
+ local prompt="${3:-Password ($dev)}"
+ local cryptsetupopts="${4:-}"
+ local luks_open _timeout
+
+ _timeout=$(getarg rd.luks.timeout)
+ _timeout="${_timeout:-0}"
+ luks_open="$(command -v cryptsetup) $cryptsetupopts luksOpen"
+ ask_for_password \
+ --ply-tries 5 \
+ --ply-cmd "$luks_open -T1 $dev $mapname" \
+ --ply-prompt "$prompt" \
+ --tty-tries 1 \
+ --tty-cmd "$luks_open -T5 -t $_timeout $dev $mapname"
+}
+
# Try to mount specified device (by path, by UUID or by label) and check
# the path with 'test'.
#
# load dm_crypt if it is not already loaded
[ -d /sys/module/dm_crypt ] || modprobe dm_crypt
-command -v ask_for_password > /dev/null || . /lib/dracut-crypt-lib.sh
+command -v luks_open_interactive > /dev/null || . /lib/dracut-crypt-lib.sh
#
# Open LUKS device
fi
if [ $ask_passphrase -ne 0 ]; then
- luks_open="$(command -v cryptsetup) $cryptsetupopts luksOpen"
- _timeout=$(getarg "rd.luks.timeout")
- _timeout=${_timeout:-0}
- ask_for_password --ply-tries 5 \
- --ply-cmd "$luks_open -T1 $device $luksname" \
- --ply-prompt "Password ($device)" \
- --tty-tries 1 \
- --tty-cmd "$luks_open -T5 -t $_timeout $device $luksname"
- unset luks_open
- unset _timeout
+ luks_open_interactive "$device" "$luksname" "Password ($device)" "$cryptsetupopts"
fi
if [ "$is_keysource" -ne 0 ] && [ "${luksname##luks-}" != "$luksname" ]; then