30 lines
1003 B
Bash
30 lines
1003 B
Bash
#!/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"
|