Files
ansible/roles/mkt-scripts/files/postfix/generate_maps.sh

25 lines
800 B
Bash
Executable File

#!/bin/bash
cd /etc/postfix
nmap -p 3306 10.201.0.4 |grep -q '3306/tcp.*open.*mysql'
if [[ $? == 1 ]]; then
exit 1
fi
MYSQL="mysql --skip-ssl -h 10.201.0.4 -u maketank -pknatekam2007 -B --database=maketank_froxlor"
#virtual_alias_maps
OLD=/etc/postfix/virtual_alias_maps
NEW=/etc/postfix/virtual_alias_maps.new
${MYSQL} -e 'select email,destination from mail_virtual where destination <> "" and destination <> " " order by email ASC'|sed -e 's@ @, @g' |sed '1d' >$NEW
if [[ $(md5sum $NEW|cut -f 1 -d ' ') != $(md5sum $OLD|cut -f 1 -d ' ') ]]; then
cp $NEW $OLD
/usr/sbin/postmap hash:$OLD
fi
#Virtual domains
NEW=/etc/postfix/virtual_mailbox_domains
${MYSQL} -e 'select domain from panel_domains where isemaildomain = "1" order by domain ASC' |tr '\n' ','|sed s/,$//|sed s/^domain,// >$NEW