|
|
@ -1,5 +1,8 @@ |
|
|
|
#!/bin/sh |
|
|
|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Define ask_yn, which asks a yes or no question and defaults to the specified choice. |
|
|
|
|
|
|
|
# Outputs 1 for yes and 0 for no |
|
|
|
|
|
|
|
|
|
|
|
ask_yn() { |
|
|
|
ask_yn() { |
|
|
|
default=${2:-"y"} |
|
|
|
default=${2:-"y"} |
|
|
|
default=$(printf "%s" "$default" | tr '[:upper:]' '[:lower:]') |
|
|
|
default=$(printf "%s" "$default" | tr '[:upper:]' '[:lower:]') |
|
|
@ -12,14 +15,14 @@ ask_yn() { |
|
|
|
esac |
|
|
|
esac |
|
|
|
|
|
|
|
|
|
|
|
while true; do |
|
|
|
while true; do |
|
|
|
trap 'exit' INT |
|
|
|
trap 'stty sane; exit' INT |
|
|
|
printf "%s (%s): " "$1" "$prompt" |
|
|
|
printf "%s (%s): " "$1" "$prompt" |
|
|
|
read -r answer || exit |
|
|
|
stty raw -echo |
|
|
|
if [ -z "$answer" ]; then |
|
|
|
answer=$(head -c 1) || exit |
|
|
|
answer="$default" |
|
|
|
stty -echo |
|
|
|
break |
|
|
|
printf "\n" |
|
|
|
fi |
|
|
|
|
|
|
|
case "$answer" in |
|
|
|
case "$answer" in |
|
|
|
|
|
|
|
"" ) answer="$default"; break;; |
|
|
|
y|Y) answer="y"; break;; |
|
|
|
y|Y) answer="y"; break;; |
|
|
|
n|N) answer="n"; break;; |
|
|
|
n|N) answer="n"; break;; |
|
|
|
esac |
|
|
|
esac |
|
|
@ -29,4 +32,6 @@ ask_yn() { |
|
|
|
y|Y) printf "1";; |
|
|
|
y|Y) printf "1";; |
|
|
|
n|N) printf "0";; |
|
|
|
n|N) printf "0";; |
|
|
|
esac |
|
|
|
esac |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ask_yn "$@" |