diff --git a/defaults/initrd.d/00-splash.sh b/defaults/initrd.d/00-splash.sh index 9c37cd8..9e58329 100755 --- a/defaults/initrd.d/00-splash.sh +++ b/defaults/initrd.d/00-splash.sh @@ -74,6 +74,90 @@ splashcmd() { esac } +# Courtesy of dracut. Licensed under GPL-2. +# Taken from: dracut/modules.d/90crypt/crypt-lib.sh +# ask_for_password +# +# Wraps around plymouth ask-for-password and adds fallback to tty password ask +# 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() { + local cmd; local prompt; local tries=3 + local ply_cmd; local ply_prompt; local ply_tries=3 + local tty_cmd; local tty_prompt; local tty_tries=3 + local ret + + while [ $# -gt 0 ]; do + 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;; + esac + shift + done + + { flock -s 9; + # Prompt for password with plymouth, if installed and running. + if is_plymouth_started + then + "${PLYMOUTH_BIN}" ask-for-password \ + --prompt="$ply_prompt" \ + --number-of-tries=$ply_tries \ + --command="$ply_cmd" + ret=$? + else + splashcmd verbose + if [ "$tty_echo_off" = yes ]; then + stty_orig="$(stty -g)" + stty -echo + fi + + local i=1 + while [ $i -le $tty_tries ]; do + [ -n "$tty_prompt" ] && \ + printf "$tty_prompt [$i/$tty_tries]:" >&2 + eval "$tty_cmd" && ret=0 && break + ret=$? + i=$(($i+1)) + [ -n "$tty_prompt" ] && printf '\n' >&2 + done + + [ "$tty_echo_off" = yes ] && stty $stty_orig + + # no need for: splashcmd quiet + # since fbsplash does not support it + if [ $ret -ne 0 ] && is_fbsplash + then + splashcmd set_msg 'Disk unlocked.' + fi + fi + } 9>/.console_lock + + [ $ret -ne 0 ] && bad_msg "Wrong password" + return $ret +} + _plymouth_init() { good_msg "Enabling Plymouth" mkdir -p /run/plymouth || return 1 diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index e754f63..f890ec3 100755 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -132,91 +132,6 @@ test_success() { fi } - -# Courtesy of dracut. Licensed under GPL-2. -# Taken from: dracut/modules.d/90crypt/crypt-lib.sh -# ask_for_password -# -# Wraps around plymouth ask-for-password and adds fallback to tty password ask -# 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() { - local cmd; local prompt; local tries=3 - local ply_cmd; local ply_prompt; local ply_tries=3 - local tty_cmd; local tty_prompt; local tty_tries=3 - local ret - - while [ $# -gt 0 ]; do - 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;; - esac - shift - done - - { flock -s 9; - # Prompt for password with plymouth, if installed and running. - if is_plymouth_started - then - "${PLYMOUTH_BIN}" ask-for-password \ - --prompt="$ply_prompt" \ - --number-of-tries=$ply_tries \ - --command="$ply_cmd" - ret=$? - else - splashcmd verbose - if [ "$tty_echo_off" = yes ]; then - stty_orig="$(stty -g)" - stty -echo - fi - - local i=1 - while [ $i -le $tty_tries ]; do - [ -n "$tty_prompt" ] && \ - printf "$tty_prompt [$i/$tty_tries]:" >&2 - eval "$tty_cmd" && ret=0 && break - ret=$? - i=$(($i+1)) - [ -n "$tty_prompt" ] && printf '\n' >&2 - done - - [ "$tty_echo_off" = yes ] && stty $stty_orig - - # no need for: splashcmd quiet - # since fbsplash does not support it - if [ $ret -ne 0 ] && is_fbsplash - then - splashcmd set_msg 'Disk unlocked.' - fi - fi - } 9>/.console_lock - - [ $ret -ne 0 ] && bad_msg "Wrong password" - return $ret -} - crypt_exec() { if [ "${CRYPT_SILENT}" = '1' ] then