summaryrefslogtreecommitdiff
path: root/vpopmail2postfixvirtual
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2001-12-12 19:52:40 +0000
committerJonas Smedegaard <dr@jones.dk>2001-12-12 19:52:40 +0000
commitc81b7f986867db292d62a1757123723b5ef66518 (patch)
treea217cf2f481ab7b3099ef76b519a4cc8e1786096 /vpopmail2postfixvirtual
Initial revision
Diffstat (limited to 'vpopmail2postfixvirtual')
-rwxr-xr-xvpopmail2postfixvirtual53
1 files changed, 53 insertions, 0 deletions
diff --git a/vpopmail2postfixvirtual b/vpopmail2postfixvirtual
new file mode 100755
index 0000000..7c37f4d
--- /dev/null
+++ b/vpopmail2postfixvirtual
@@ -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