#!/bin/bash
name=$1 conf=$2
echo >&2 "$0 $1 $2"
sed -i '
	s/\t10\tmx2$/\t20\tmx2/;
	/\<mx[0-9]\>/d;
' "$conf"

(
echo

cat <<-_EOT_

$name.	MX	10	in1-smtp.messagingengine.com.
$name.	MX	20	in2-smtp.messagingengine.com.

$name. IN TXT "v=spf1 ip4:182.160.154.142 ip4:71.19.155.193 include:spf.messagingengine.com ~all"
fm1._domainkey IN CNAME fm1.$name.dkim.fmhosted.com.
fm2._domainkey IN CNAME fm2.$name.dkim.fmhosted.com.
fm3._domainkey IN CNAME fm3.$name.dkim.fmhosted.com.
_EOT_

for file in "/etc/bind/freens/$name.d"/*; do
	if [ ! -e "$file" ]; then
		continue
	fi
	echo
	cat "$file"
done
) >> "$conf"
