From 80c3351124680d06fbbfa9a43dfd359d00246c3c Mon Sep 17 00:00:00 2001 From: Damir Dzeko Date: Mon, 21 Mar 2005 12:48:18 +0000 Subject: [PATCH] r16: More untested functions. - cp_yes_no - simple y/n dialog function --- functions-more.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 functions-more.sh diff --git a/functions-more.sh b/functions-more.sh new file mode 100644 index 0000000..be66994 --- /dev/null +++ b/functions-more.sh @@ -0,0 +1,33 @@ +# by ddzeko, Mon, 21 Mar 2005 13:35:42 +0100 +cn_yes_no () { + [ "$CP_SCRIPT_DEBUG" ] && set -vx + local prompt answer + prompt=$1 + [ "$prompt" ] || prompt="Are you sure?" + RET="" + + # check to prevent user from using this when debconf is active + # (it would break communication with its backend - uses stdin/out) + if [ "$DEBCONF_REDIR" ]; then + echo "cn_yes_no: debconf redirection detected" >&2 + return 1 + fi + + echo -n "$prompt (y)es/(n)o: " + read answer + case $answer in + y*) + echo + RET=y + ;; + n*) + echo + RET=n + ;; + *) + echo + echo "Please read the message and choose y or n" + cn_yes_no + ;; + esac +} -- 1.7.10.4