summaryrefslogtreecommitdiff
path: root/libalpine.sh.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2009-08-19 14:19:28 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2009-08-19 14:19:28 +0000
commit7ba8c4c2c09fc6df6c0c34e0d953ef3bc21224a0 (patch)
tree3e4d9b559060228e1057ca518580bd34025f7c2e /libalpine.sh.in
parent8bee519d1aa741ef8cb7677b77b0a717c3395648 (diff)
downloadalpine-conf-7ba8c4c2c09fc6df6c0c34e0d953ef3bc21224a0.zip
libalpine: imported some funcs from openbsd installer
Diffstat (limited to 'libalpine.sh.in')
-rwxr-xr-xlibalpine.sh.in37
1 files changed, 37 insertions, 0 deletions
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
+}
+
+