From fdb819852e9296852ff17837dbdd6697e0138ff1 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Thu, 2 Feb 2023 17:09:33 +0100 Subject: [PATCH] Improve purge script --- scripts/purge_user.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/purge_user.sh b/scripts/purge_user.sh index 79e33be1..07d4a354 100755 --- a/scripts/purge_user.sh +++ b/scripts/purge_user.sh @@ -51,21 +51,28 @@ for maildir in "${storage}"/mail/*; do fi done -# output actions if [[ ${#users[@]} -eq 0 ]]; then - echo "Nothing to be done." + echo "Nothing to clean up." exit 0 fi + +# is roundcube webmail in use? +webmail=false +docker compose exec webmail test -e /data/roundcube.db 2>/dev/null && webmail=true + +# output actions if ${unknown}; then echo "# To delete maildirs unknown to mailu, run:" for email in "${!users[@]}"; do [[ "${users[${email}]}" == "unknown" ]] || continue - echo "rm -rf '${storage}/mail/${email}'" + echo -n "rm -rf '${storage}/mail/${email}'" + ${webmail} && \ + echo -n " && docker compose exec -T webmail su mailu -c \"/var/www/roundcube/bin/deluser.sh --host=front '${email}'\"" + echo done echo fi if ${disabled}; then - webmail=true; docker compose ps webmail &>/dev/null || webmail=false echo "# To purge disabled users, run:" for email in "${!users[@]}"; do [[ "${users[${email}]}" == "disabled" ]] || continue @@ -76,4 +83,3 @@ if ${disabled}; then done echo fi -