From 7ba8c4c2c09fc6df6c0c34e0d953ef3bc21224a0 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 19 Aug 2009 14:19:28 +0000 Subject: libalpine: imported some funcs from openbsd installer --- libalpine.sh.in | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/libalpine.sh.in b/libalpine.sh.in index b47fa71..569264c 100755 --- a/libalpine.sh.in +++ b/libalpine.sh.in @@ -76,3 +76,40 @@ invalid_ip() { cfg_add() { [ -z "$NOCOMMIT" ] && lbu_add "$@" } + +# from OpenBSD installer + +# Ask for a password, saving the input in $resp. +# Display $1 as the prompt. +# *Don't* allow the '!' options that ask does. +# *Don't* echo input. +# *Don't* interpret "\" as escape character. +askpass() { + echo -n "$1 " + set -o noglob + stty -echo + read -r resp + stty echo + set +o noglob + echo +} + +# Ask for a password twice, saving the input in $_password +askpassword() { + local _oifs=$IFS + IFS= + while :; do + askpass "Password for $1 account? (will not echo)" + _password=$resp + + askpass "Password for $1 account? (again)" + # N.B.: Need quotes around $resp and $_password to preserve leading + # or trailing spaces. + [ "$resp" = "$_password" ] && break + + echo "Passwords do not match, try again." + done + IFS=$_oifs +} + + -- cgit v1.2.3