Add migration scripts and other fixes

This commit is contained in:
2026-09-14 20:36:10 +03:00
parent 4cb65a6f52
commit 1cd38af60e
12 changed files with 604 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Dumps accounts + aliases from a docker-mailserver config directory into a
# migration CSV skeleton (email,new_password,old_password,aliases,quota_mb).
# Passwords are left blank: docker-mailserver only stores irreversible hashes.
set -euo pipefail
CONFIG_DIR="${1:?Usage: $0 /path/to/docker-mailserver/config}"
ACCOUNTS_FILE="$CONFIG_DIR/postfix-accounts.cf"
ALIASES_FILE="$CONFIG_DIR/postfix-virtual.cf"
if [[ ! -f "$ACCOUNTS_FILE" ]]; then
echo "postfix-accounts.cf not found under $CONFIG_DIR" >&2
exit 1
fi
echo "email,new_password,old_password,aliases,quota_mb"
while IFS='|' read -r email _hash; do
[[ -z "$email" || "$email" == \#* ]] && continue
aliases=""
if [[ -f "$ALIASES_FILE" ]]; then
# postfix-virtual.cf lines look like: alias@domain destination@domain
aliases=$(awk -v dest="$email" '$2 == dest { sub(/@.*/, "", $1); printf "%s;", $1 }' "$ALIASES_FILE")
aliases="${aliases%;}"
fi
echo "$email,,,${aliases},"
done < "$ACCOUNTS_FILE"