blob: 12af73f3f2fb0ebcdbdffdb898f9eb070f1d8a5b (
plain)
- #!/bin/bash
- #
- # /usr/local/sbin/localmkpostfixvirtual
- # Copyright 2001-2002 Jonas Smedegaard <dr@jones.dk>
- #
- # $Id: localmkpostfixvirtual,v 1.8 2002-09-04 23:35:52 jonas Exp $
- #
- # Generate virtual file for postfix
- #
- # Hints are stored in the "Other" field (using chfn).
- #
- # Each user should have space-separated hints like "mailname1@ mailname2@gid1 mailname3@gid2".
- #
- # The user of each mailgroup should have hints like "@domain1 @domain2"
- # for each hosted domain.
- #
- # Optional: More than one mailgroup can be grouped: 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@"
- # (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)?$" | sed -e 's/@.*//'; }
- 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
- echo "$maildomain VIRTUAL"
- uid_seen=""
- for mailaccountchunk in `get_other_field root`; do
- for mailaccount in `get_account $mailaccountchunk`; do
- echo "$mailaccount@$maildomain root"
- uid_seen=true
- done
- done
- if [ ! $uid_seen ]; then
- echo "postmaster@$maildomain root"
- fi
- echo
- 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 | sort`; do
- echo "# `get_fullname_field $uid` (`get_groups $uid`)"
- uid_seen=""
- for mailaccountchunk in `get_other_field $uid`; do
- for mailaccount in `get_account $mailaccountchunk`; do
- echo "$mailaccount@$maildomain $uid"
- uid_seen=true
- done
- done
- if [ ! $uid_seen ]; then
- echo "#WARNING: No addresses for $uid"
- fi
- echo
- done
- done
- done
- done
|