blob: 79ad78f0386a8104c1aac18873f3894dbe3e8b55 (
plain)
- #!/bin/bash
- #
- # /usr/local/sbin/localmkpostfixvirtual
- # Copyright 2001-2002 Jonas Smedegaard <dr@jones.dk>
- #
- # $Id: localmkpostfixvirtual,v 1.9 2002-11-03 03:06:32 jonas Exp $
- #
- # Generate virtual file for postfix
- #
- # Hints are stored in the "Other" field (using chfn).
- #
- # Each user should have space-separated hints like this:
- # "mailname1@ mailname2@mailgroup1 mailname3@mailgroup2 mailname4@maildomain7".
- #
- # The user of each mailgroup should have hints like "@domain1 @domain2"
- # for each hosted maildomain.
- #
- # Optional: Several mailgroups can be tied together (when amount of hints
- # exceeds the limit of the "Other" field: List them all in
- # "Office" or "roomnumber" field of primary mailgroup (include the
- # primary mailgroup itself!).
- #
- # Optional: root can have hints like "postmaster@ hostmaster@ support@"
- # for default accounts tied to the sysadmin (default: "postmaster@").
- #
- # Suggestion: Add mailgroup users like this:
- # adduser --system --no-create-home --group --disabled-password <uid>
- #
- # TODO: reuse getent requests (drastically improves speed)
- # TODO: Write command "members" as internal code
- #
- function get_fullname_field() { getent passwd $1 | awk -F: '{print $5}' | awk -F, '{print $1}'; }
- function get_roomnumber_field() { getent passwd $1 | awk -F: '{print $5}' | awk -F, '{print $2}'; }
- function get_other_field() { getent passwd $1 | awk -F: '{print $5}' | awk -F, '{print $5}'; }
- function get_groups() { groups $1 | sed -e 's/^.*: //' -e "s/\( \+\|^\)$1\( \+\|$\)/\1/"; }
- function get_domain() { echo $1 | egrep "^@[\.[:alnum:]-]+$" | sed -e 's/@//'; }
- function get_account() { echo $1 | egrep "^[\.[:alnum:]-]+@($gid|$maildomain)?$" | sed -e 's/@.*//'; }
- function print_accounts() {
- uid=$1
- maildomain=$2
- pre_text=$3
- post_fallback_text=$4
- test -n "$pre_text" && echo "$pre_text"
- uid_seen=""
- for mailaccountchunk in `get_other_field $uid`; do
- for mailaccount in `get_account $mailaccountchunk`; do
- echo "$mailaccount@$maildomain $uid"
- uid_seen=1
- done
- done
- test -n "$post_fallback_text" -a -z "$uid_seen" && echo "$post_fallback_text"
- echo
- }
- loop=""
- for gid in $@; do
- for maildomainchunk in `get_other_field $gid`; do
- for maildomain in `get_domain $maildomainchunk`; do
- if [ $loop ]; then
- echo
- echo "##################################################################"
- echo
- fi
- loop=true
- print_accounts root "$maildomain" "$maildomain VIRTUAL" "postmaster@$maildomain root"
- mailusers=""
- mailgroups=`get_roomnumber_field $gid`
- [ -z "$mailgroups" ] && mailgroups=$gid
- for mailgroup in $mailgroups; do
- mailusers="$mailusers `members $mailgroup`"
- done
- # for uid in `members $gid | sort`; do
- for uid in `echo $mailusers | tsort | uniq | grep -v $gid | sort`; do
- print_accounts $uid "$maildomain" "# `get_fullname_field $uid` (`get_groups $uid`)" "#WARNING: No addresses for $uid"
- done
- done
- done
- done
|