Skip to content

Commit fdb8198

Browse files
committed
Improve purge script
1 parent dd80fde commit fdb8198

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

scripts/purge_user.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,28 @@ for maildir in "${storage}"/mail/*; do
5151
fi
5252
done
5353

54-
# output actions
5554
if [[ ${#users[@]} -eq 0 ]]; then
56-
echo "Nothing to be done."
55+
echo "Nothing to clean up."
5756
exit 0
5857
fi
58+
59+
# is roundcube webmail in use?
60+
webmail=false
61+
docker compose exec webmail test -e /data/roundcube.db 2>/dev/null && webmail=true
62+
63+
# output actions
5964
if ${unknown}; then
6065
echo "# To delete maildirs unknown to mailu, run:"
6166
for email in "${!users[@]}"; do
6267
[[ "${users[${email}]}" == "unknown" ]] || continue
63-
echo "rm -rf '${storage}/mail/${email}'"
68+
echo -n "rm -rf '${storage}/mail/${email}'"
69+
${webmail} && \
70+
echo -n " && docker compose exec -T webmail su mailu -c \"/var/www/roundcube/bin/deluser.sh --host=front '${email}'\""
71+
echo
6472
done
6573
echo
6674
fi
6775
if ${disabled}; then
68-
webmail=true; docker compose ps webmail &>/dev/null || webmail=false
6976
echo "# To purge disabled users, run:"
7077
for email in "${!users[@]}"; do
7178
[[ "${users[${email}]}" == "disabled" ]] || continue
@@ -76,4 +83,3 @@ if ${disabled}; then
7683
done
7784
echo
7885
fi
79-

0 commit comments

Comments
 (0)