summaryrefslogtreecommitdiff
path: root/localmkpostfixvirtual
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2002-01-24 17:03:36 +0000
committerJonas Smedegaard <dr@jones.dk>2002-01-24 17:03:36 +0000
commit536365c05122a146065251447352ca0cf8c21bda (patch)
tree79fbd3c2d97578af7a3decc23649d4304f04b2b7 /localmkpostfixvirtual
parenta34f2136864d740cb222d56baf48ff06f0ca3ed8 (diff)
Re-rename badly renamed vpopmail2postfixvirtual to localmkpostfixvirtual.
Diffstat (limited to 'localmkpostfixvirtual')
-rwxr-xr-xlocalmkpostfixvirtual53
1 files changed, 53 insertions, 0 deletions
diff --git a/localmkpostfixvirtual b/localmkpostfixvirtual
new file mode 100755
index 0000000..7c37f4d
--- /dev/null
+++ b/localmkpostfixvirtual
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+# Generate virtual file for postfix
+#
+# Each user should have space-separated hints like "mailname1@ mailname2@gid1 mailname3@gid2"
+# stored in the "Other" field (using chfn).
+#
+# The user of each mailgroup should have hints like "@domain1 @domain2" for each hosted domain
+# stored in the "Other" field (using chfn).
+
+#TODO: reuse getent requests (drastically improves speed with multiple domains)
+
+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_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"
+ echo "postmaster@$maildomain root"
+ echo
+ mailusers=""
+ for mailgroup in `get_roomnumber_field $gid`; 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_roomnumber_field $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