remove 'clean' option from script

This commit is contained in:
Asif Bacchus 2020-03-14 19:12:04 -06:00
parent 7a58e1b513
commit d733687742

View File

@ -45,13 +45,11 @@ cyan=$(tput setaf 6)
err=$(tput bold)$(tput setaf 1) err=$(tput bold)$(tput setaf 1)
magenta=$(tput setaf 5) magenta=$(tput setaf 5)
norm=$(tput sgr0) norm=$(tput sgr0)
red=$(tput setaf 1)
yellow=$(tput setaf 3) yellow=$(tput setaf 3)
width=$(tput cols) width=$(tput cols)
### parameter defaults ### parameter defaults
scriptName="$( basename "$0" )" scriptName="$( basename "$0" )"
clean=false
restore=false restore=false
container_name="ab-openldap" container_name="ab-openldap"
volume_data="ab-openldap_data" volume_data="ab-openldap_data"
@ -154,10 +152,6 @@ while [ $# -gt 0 ]; do
# start shell instead of default CMD # start shell instead of default CMD
shell=true shell=true
;; ;;
--clean)
# stop if necessary, delete volumes
clean=true
;;
--restore) --restore)
# restore backup # restore backup
restore=true restore=true
@ -214,50 +208,9 @@ done
### process main operations ### process main operations
# cleanup containers and volumes
if [ $clean = true ]; then
# display warning and confirm user's intentions
printf "\nThis will stop and remove all ab-openldap containers %sAND REMOVE ALL PERSISTENT DATA VOLUMES%s. Please ensure you have a backup and understand how to restore your data.\n" \
"$red" "$norm"
printf "%sThis action CANNOT be undone!%s\n\n" \
"$red" "$norm"
prompt_yn
# get all ab-openldap containers
containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}")
# check for null value -- no containers to remove
if [ -z "$containers" ]; then
consoleError '0' 'No openldap containers to remove.'
fi
# iterate containers, stop them and remove straggling volumes
set -- dummy $containers
shift
for container; do
printf "\n%sFound %s -- processing:%s\n" \
"$cyan" "$container" "$norm"
# stop container
printf "\t%sStopping container...%s\n" "$red" "$norm"
docker stop ${container} > /dev/null 2>&1
# find volumes
volumes=$(docker inspect --format '{{ range .Mounts }}{{ println .Name }}{{ end }}' ${container})
# remove container
printf "\t%sRemoving container...%s\n" "$red" "$norm"
docker rm -f ${container} > /dev/null 2>&1
# pause to allow write flushing
sleep 3
# iterate volumes
set -- dummy2 $volumes
shift
for volume; do
printf "\t%sRemoving volume '%s'...%s\n" "$red" "$volume" "$norm"
docker volume rm -f ${volume} > /dev/null 2>&1
done
printf "%s...done%s\n" "$cyan" "$norm"
done
# automatically restore backups using a temporary container to create necessary # automatically restore backups using a temporary container to create necessary
# volumes # volumes
elif [ $restore = true ]; then if [ $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"