replace confirmation loops with func prompt_yn
This commit is contained in:
parent
a77b73e835
commit
c6723b6c54
@ -17,6 +17,27 @@ textblock () {
|
||||
printf "%s\n" "$1" | fold -w "$width" -s
|
||||
}
|
||||
|
||||
prompt_yn () {
|
||||
# confirmation loop
|
||||
while true; do
|
||||
printf "%sAre you sure you want to continue? (y/n)%s " \
|
||||
"$cyan" "$norm"
|
||||
read -r yn
|
||||
case "$yn" in
|
||||
[Yy]*)
|
||||
break
|
||||
;;
|
||||
[Nn]*)
|
||||
printf "\n"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
printf "Please answer 'y' or 'n'.\n"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# text formatting presets
|
||||
bold=$(tput bold)
|
||||
@ -198,25 +219,7 @@ if [ $clean = true ]; then
|
||||
"$red" "$norm"
|
||||
printf "%sThis action CANNOT be undone!%s\n\n" \
|
||||
"$red" "$norm"
|
||||
|
||||
# confirmation loop
|
||||
while true; do
|
||||
printf "%sAre you sure you want to continue? (yes/no)%s " \
|
||||
"$cyan" "$norm"
|
||||
read -r yn
|
||||
case "$yn" in
|
||||
[Yy]*)
|
||||
break
|
||||
;;
|
||||
[Nn]*)
|
||||
printf "\n"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
printf "Please answer 'y' or 'n'.\n"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
prompt_yn
|
||||
|
||||
# get all ab-openldap containers
|
||||
containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}")
|
||||
@ -251,28 +254,12 @@ if [ $clean = true ]; then
|
||||
printf "%s...done%s\n" "$cyan" "$norm"
|
||||
done
|
||||
elif [ $restore = true ]; then
|
||||
# restore backup
|
||||
printf "%s\n*** Restoring Backup ***\n\n%s" "$magenta" "$norm"
|
||||
printf "To avoid errors due to existing files, this script will delete any volumes that have the following names (based on --data and --ldif):\n"
|
||||
printf "\t%s\n\t%s\n" "$volume_data" "$volume_ldif"
|
||||
# confirmation loop
|
||||
while true; do
|
||||
printf "%sDo you want to continue? (yes/no)%s " \
|
||||
"$cyan" "$norm"
|
||||
read -r yn
|
||||
case "$yn" in
|
||||
[Yy]*)
|
||||
break
|
||||
;;
|
||||
[Nn]*)
|
||||
printf "\n"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
printf "Please answer 'y' or 'n'.\n"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# restore backup
|
||||
printf "%s\n*** Restoring Backup ***\n\n%s" "$magenta" "$norm"
|
||||
printf "To avoid errors due to existing files, this script will delete any volumes that have the following names (based on --data and --ldif):\n"
|
||||
printf "\t%s\n\t%s\n" "$volume_data" "$volume_ldif"
|
||||
prompt_yn
|
||||
|
||||
# delete any conflicting volumes
|
||||
docker volume rm ${volume_data} > /dev/null 2>&1
|
||||
docker volume rm ${volume_ldif} > /dev/null 2>&1
|
||||
|
Loading…
Reference in New Issue
Block a user