blob: 6662d555843514a1b3d6d69a94f35185f24a7dfd (
plain)
- #!/bin/sh
- #
- # /usr/local/sbin/localmailrecipientsdump
- # Copyright 2004-2006 Jonas Smedegaard <dr@jones.dk>
- #
- # Dump a list of all local mail destinations
- #
- set -e
- pfdir="/etc/postfix"
- firstitem() {
- set -e
- file="$1"
- cat "$file" | grep -v '^#' | sed 's/#.*//' | head -n 1
- }
- localdomains() {
- set -e
- postconf -h mydestination | tr ',' ' '
- }
- aliasmaps() {
- set -e
- postconf -h alias_maps | tr ',' ' '
- }
- virtualmaps() {
- set -e
- perl -ne 's/^virtual_maps\s*=\s*// and print' < /etc/postfix/main.cf | tr ',' ' '
- }
- accounts() {
- set -e
- (
- getent passwd | perl -ne 's/:.*// and s/^([a-z]\S*).*/$1/ and print'
- for map in $(aliasmaps); do
- postalias -s $map | perl -ne 's/^([a-z]\S*):.*/$1/ and print'
- done
- ) | sort -u
- }
- mkrecipientsmap() {
- for domain in $(localdomains); do
- for account in $(accounts); do
- echo "$account@$domain OK"
- done
- done
- for map in $(virtualmaps); do
- postmap -s $map | perl -ne 's/^([a-z]\S*\@\S+)\s.*/$1 OK/ and print'
- done
- }
- redpill="$(firstitem "/etc/local-ORG/redpill")"
- realm="$(firstitem "/etc/local-ORG/realm")"
- mkrecipientsmap | sort -t@ -k2 -k1 > "/etc/local-$redpill/$realm/mailrecipients"
|