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
|
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
|
# text formatting presets
|
||||||
bold=$(tput bold)
|
bold=$(tput bold)
|
||||||
@ -198,25 +219,7 @@ if [ $clean = true ]; then
|
|||||||
"$red" "$norm"
|
"$red" "$norm"
|
||||||
printf "%sThis action CANNOT be undone!%s\n\n" \
|
printf "%sThis action CANNOT be undone!%s\n\n" \
|
||||||
"$red" "$norm"
|
"$red" "$norm"
|
||||||
|
prompt_yn
|
||||||
# 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
|
|
||||||
|
|
||||||
# get all ab-openldap containers
|
# get all ab-openldap containers
|
||||||
containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}")
|
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"
|
printf "%s...done%s\n" "$cyan" "$norm"
|
||||||
done
|
done
|
||||||
elif [ $restore = true ]; then
|
elif [ $restore = true ]; then
|
||||||
# restore backup
|
# restore backup
|
||||||
printf "%s\n*** Restoring Backup ***\n\n%s" "$magenta" "$norm"
|
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 "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"
|
printf "\t%s\n\t%s\n" "$volume_data" "$volume_ldif"
|
||||||
# confirmation loop
|
prompt_yn
|
||||||
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
|
|
||||||
# delete any conflicting volumes
|
# delete any conflicting volumes
|
||||||
docker volume rm ${volume_data} > /dev/null 2>&1
|
docker volume rm ${volume_data} > /dev/null 2>&1
|
||||||
docker volume rm ${volume_ldif} > /dev/null 2>&1
|
docker volume rm ${volume_ldif} > /dev/null 2>&1
|
||||||
|
Loading…
Reference in New Issue
Block a user