From 9de2e841384910beaa6ea88af0b4481a3290e40b Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 3 Nov 2002 03:06:32 +0000 Subject: * Rewrite some code as a function * Allow "Other"-field to contain mailname@fqdn style hints (in addition to mailname@mailgroup ones) * Suppress empty-entry warning for mailgroup --- localmkpostfixvirtual | 60 +++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'localmkpostfixvirtual') diff --git a/localmkpostfixvirtual b/localmkpostfixvirtual index 12af73f..79ad78f 100755 --- a/localmkpostfixvirtual +++ b/localmkpostfixvirtual @@ -3,23 +3,25 @@ # /usr/local/sbin/localmkpostfixvirtual # Copyright 2001-2002 Jonas Smedegaard # -# $Id: localmkpostfixvirtual,v 1.8 2002-09-04 23:35:52 jonas Exp $ +# $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 "mailname1@ mailname2@gid1 mailname3@gid2". +# 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 domain. +# for each hosted maildomain. # -# Optional: More than one mailgroup can be grouped: List them all in +# 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@" -# (default: "postmaster@"). +# for default accounts tied to the sysadmin (default: "postmaster@"). # # Suggestion: Add mailgroup users like this: # adduser --system --no-create-home --group --disabled-password @@ -33,7 +35,25 @@ function get_roomnumber_field() { getent passwd $1 | awk -F: '{print $5}' | awk 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/@.*//'; } +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 @@ -45,18 +65,7 @@ for gid in $@; do 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 + print_accounts root "$maildomain" "$maildomain VIRTUAL" "postmaster@$maildomain root" mailusers="" mailgroups=`get_roomnumber_field $gid` [ -z "$mailgroups" ] && mailgroups=$gid @@ -64,19 +73,8 @@ for gid in $@; 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 + 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 -- cgit v1.2.3