contrib: dracut: zfs-lib: simplify ask_for_password
The only user is mount-zfs.sh (non-systemd systems), so reduce it to what it needs Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13291
This commit is contained in:
parent
fec2c613a4
commit
5d31169d7c
|
@ -56,9 +56,9 @@ if import_pool "${ZFS_POOL}" ; then
|
||||||
if [ "$KEYSTATUS" = "unavailable" ]; then
|
if [ "$KEYSTATUS" = "unavailable" ]; then
|
||||||
# decrypt them
|
# decrypt them
|
||||||
ask_for_password \
|
ask_for_password \
|
||||||
--tries 5 \
|
5 \
|
||||||
--prompt "Encrypted ZFS password for ${ENCRYPTIONROOT}: " \
|
"Encrypted ZFS password for ${ENCRYPTIONROOT}: " \
|
||||||
--cmd "zfs load-key '${ENCRYPTIONROOT}'"
|
"zfs load-key '${ENCRYPTIONROOT}'"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -122,44 +122,14 @@ for_relevant_root_children() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# ask_for_password
|
# ask_for_password tries prompt cmd
|
||||||
#
|
#
|
||||||
# Wraps around plymouth ask-for-password and adds fallback to tty password ask
|
# Wraps around plymouth ask-for-password and adds fallback to tty password ask
|
||||||
# if plymouth is not present.
|
# if plymouth is not present.
|
||||||
#
|
|
||||||
# --cmd command
|
|
||||||
# Command to execute. Required.
|
|
||||||
# --prompt prompt
|
|
||||||
# Password prompt. Note that function already adds ':' at the end.
|
|
||||||
# Recommended.
|
|
||||||
# --tries n
|
|
||||||
# How many times repeat command on its failure. Default is 3.
|
|
||||||
# --ply-[cmd|prompt|tries]
|
|
||||||
# Command/prompt/tries specific for plymouth password ask only.
|
|
||||||
# --tty-[cmd|prompt|tries]
|
|
||||||
# Command/prompt/tries specific for tty password ask only.
|
|
||||||
# --tty-echo-off
|
|
||||||
# Turn off input echo before tty command is executed and turn on after.
|
|
||||||
# It's useful when password is read from stdin.
|
|
||||||
ask_for_password() {
|
ask_for_password() {
|
||||||
ply_tries=3
|
tries="$1"
|
||||||
tty_tries=3
|
prompt="$2"
|
||||||
while [ "$#" -gt 0 ]; do
|
cmd="$3"
|
||||||
case "$1" in
|
|
||||||
--cmd) ply_cmd="$2"; tty_cmd="$2"; shift;;
|
|
||||||
--ply-cmd) ply_cmd="$2"; shift;;
|
|
||||||
--tty-cmd) tty_cmd="$2"; shift;;
|
|
||||||
--prompt) ply_prompt="$2"; tty_prompt="$2"; shift;;
|
|
||||||
--ply-prompt) ply_prompt="$2"; shift;;
|
|
||||||
--tty-prompt) tty_prompt="$2"; shift;;
|
|
||||||
--tries) ply_tries="$2"; tty_tries="$2"; shift;;
|
|
||||||
--ply-tries) ply_tries="$2"; shift;;
|
|
||||||
--tty-tries) tty_tries="$2"; shift;;
|
|
||||||
--tty-echo-off) tty_echo_off=yes;;
|
|
||||||
*) echo "ask_for_password(): wrong opt '$1'" >&2;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
{
|
{
|
||||||
flock -s 9
|
flock -s 9
|
||||||
|
@ -167,26 +137,19 @@ ask_for_password() {
|
||||||
# Prompt for password with plymouth, if installed and running.
|
# Prompt for password with plymouth, if installed and running.
|
||||||
if plymouth --ping 2>/dev/null; then
|
if plymouth --ping 2>/dev/null; then
|
||||||
plymouth ask-for-password \
|
plymouth ask-for-password \
|
||||||
--prompt "$ply_prompt" --number-of-tries="$ply_tries" | \
|
--prompt "$prompt" --number-of-tries="$tries" | \
|
||||||
eval "$ply_cmd"
|
eval "$cmd"
|
||||||
ret=$?
|
ret=$?
|
||||||
else
|
else
|
||||||
if [ "$tty_echo_off" = yes ]; then
|
|
||||||
stty_orig="$(stty -g)"
|
|
||||||
stty -echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
i=1
|
i=1
|
||||||
while [ "$i" -le "$tty_tries" ]; do
|
while [ "$i" -le "$tries" ]; do
|
||||||
[ -n "$tty_prompt" ] && \
|
printf "%s [%i/%i]:" "$prompt" "$i" "$tries" >&2
|
||||||
printf "%s [%i/%i]:" "$tty_prompt" "$i" "$tty_tries" >&2
|
eval "$cmd" && ret=0 && break
|
||||||
eval "$tty_cmd" && ret=0 && break
|
|
||||||
ret=$?
|
ret=$?
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
[ -n "$tty_prompt" ] && printf '\n' >&2
|
printf '\n' >&2
|
||||||
done
|
done
|
||||||
unset i
|
unset i
|
||||||
[ "$tty_echo_off" = yes ] && stty "$stty_orig"
|
|
||||||
fi
|
fi
|
||||||
} 9>/.console_lock
|
} 9>/.console_lock
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue