refactoring dns_update: use global vars stored in /etc/mailinabox.conf
This commit is contained in:
parent
548cc8a0f6
commit
9cd5fc34a9
3 changed files with 10 additions and 31 deletions
|
@ -11,30 +11,11 @@
|
||||||
|
|
||||||
apt-get -qq -y install nsd3
|
apt-get -qq -y install nsd3
|
||||||
|
|
||||||
# Get configuraton information.
|
|
||||||
|
|
||||||
if [ -z "$PUBLIC_HOSTNAME" ]; then
|
|
||||||
PUBLIC_HOSTNAME=example.org
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$PUBLIC_IP" ]; then
|
|
||||||
# works on EC2 only...
|
|
||||||
PUBLIC_IP=`wget -q -O- http://instance-data/latest/meta-data/public-ipv4`
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Prepare nsd3's configuration.
|
# Prepare nsd3's configuration.
|
||||||
|
|
||||||
sudo mkdir -p /var/run/nsd3
|
sudo mkdir -p /var/run/nsd3
|
||||||
mkdir -p "$STORAGE_ROOT/dns";
|
mkdir -p "$STORAGE_ROOT/dns";
|
||||||
|
|
||||||
# Store our desired IP address (to put in the zone files) for later.
|
|
||||||
# Also store our primary hostname, which we'll use for all DKIM signatures
|
|
||||||
# in case the user is only delegating MX and we aren't setting DKIM on
|
|
||||||
# the main DNS.
|
|
||||||
|
|
||||||
echo $PUBLIC_IP > $STORAGE_ROOT/dns/our_ip
|
|
||||||
echo $PUBLIC_HOSTNAME > $STORAGE_ROOT/dns/primary_hostname
|
|
||||||
|
|
||||||
# Create the default zone if it doesn't exist.
|
# Create the default zone if it doesn't exist.
|
||||||
|
|
||||||
if [ ! -f "$STORAGE_ROOT/dns/$PUBLIC_HOSTNAME.txt" ]; then
|
if [ ! -f "$STORAGE_ROOT/dns/$PUBLIC_HOSTNAME.txt" ]; then
|
||||||
|
|
|
@ -8,10 +8,7 @@
|
||||||
|
|
||||||
# This script is safe to run on its own.
|
# This script is safe to run on its own.
|
||||||
|
|
||||||
# Load $STORAGE_ROOT, $PUBLIC_IP, and $PRIMARY_HOSTNAME.
|
source /etc/mailinabox.conf # load global vars
|
||||||
source /etc/mailinabox.conf
|
|
||||||
PUBLIC_IP=`cat $STORAGE_ROOT/dns/our_ip`
|
|
||||||
PRIMARY_HOSTNAME=`cat $STORAGE_ROOT/dns/primary_hostname`
|
|
||||||
|
|
||||||
# Ensure a zone file exists for every domain name in use by a mail user.
|
# Ensure a zone file exists for every domain name in use by a mail user.
|
||||||
for mail_user in `tools/mail.py user`; do
|
for mail_user in `tools/mail.py user`; do
|
||||||
|
@ -69,7 +66,7 @@ for fn in $STORAGE_ROOT/dns/*.txt; do
|
||||||
\$ORIGIN $zone. ; default zone domain
|
\$ORIGIN $zone. ; default zone domain
|
||||||
\$TTL 86400 ; default time to live
|
\$TTL 86400 ; default time to live
|
||||||
|
|
||||||
@ IN SOA ns1.$PRIMARY_HOSTNAME. hostmaster.$PRIMARY_HOSTNAME. (
|
@ IN SOA ns1.$PUBLIC_HOSTNAME. hostmaster.$PUBLIC_HOSTNAME. (
|
||||||
$serial ; serial number
|
$serial ; serial number
|
||||||
28800 ; Refresh
|
28800 ; Refresh
|
||||||
7200 ; Retry
|
7200 ; Retry
|
||||||
|
@ -77,18 +74,18 @@ for fn in $STORAGE_ROOT/dns/*.txt; do
|
||||||
86400 ; Min TTL
|
86400 ; Min TTL
|
||||||
)
|
)
|
||||||
|
|
||||||
NS ns1.$PRIMARY_HOSTNAME.
|
NS ns1.$PUBLIC_HOSTNAME.
|
||||||
NS ns2.$PRIMARY_HOSTNAME.
|
NS ns2.$PUBLIC_HOSTNAME.
|
||||||
IN A $PUBLIC_IP
|
IN A $PUBLIC_IP
|
||||||
MX 10 $PRIMARY_HOSTNAME.
|
MX 10 $PUBLIC_HOSTNAME.
|
||||||
|
|
||||||
300 TXT "v=spf1 mx -all"
|
300 TXT "v=spf1 mx -all"
|
||||||
|
|
||||||
www IN A $PUBLIC_IP
|
www IN A $PUBLIC_IP
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# In PRIMARY_HOSTNAME, also define ns1 and ns2.
|
# In PUBLIC_HOSTNAME, also define ns1 and ns2.
|
||||||
if [ "$zone" = $PRIMARY_HOSTNAME ]; then
|
if [ "$zone" = $PUBLIC_HOSTNAME ]; then
|
||||||
cat >> /etc/nsd3/zones/$fn2 << EOF;
|
cat >> /etc/nsd3/zones/$fn2 << EOF;
|
||||||
ns1 IN A $PUBLIC_IP
|
ns1 IN A $PUBLIC_IP
|
||||||
ns2 IN A $PUBLIC_IP
|
ns2 IN A $PUBLIC_IP
|
||||||
|
@ -112,12 +109,12 @@ EOF
|
||||||
# the selector, and the path to the private key.
|
# the selector, and the path to the private key.
|
||||||
#
|
#
|
||||||
# Just in case we don't actually host the DNS for all domains of our mail users,
|
# Just in case we don't actually host the DNS for all domains of our mail users,
|
||||||
# we assume that DKIM is at least configured in the DNS of $PRIMARY_HOSTNAME and
|
# we assume that DKIM is at least configured in the DNS of $PUBLIC_HOSTNAME and
|
||||||
# we use that host for all DKIM signatures.
|
# we use that host for all DKIM signatures.
|
||||||
#
|
#
|
||||||
# In SigningTable, we map every email address to a key record called $zone.
|
# In SigningTable, we map every email address to a key record called $zone.
|
||||||
# Then we specify for the key record named $zone its domain, selector, and key.
|
# Then we specify for the key record named $zone its domain, selector, and key.
|
||||||
echo "$zone $PRIMARY_HOSTNAME:mail:$STORAGE_ROOT/mail/dkim/mail.private" >> /etc/opendkim/KeyTable
|
echo "$zone $PUBLIC_HOSTNAME:mail:$STORAGE_ROOT/mail/dkim/mail.private" >> /etc/opendkim/KeyTable
|
||||||
echo "*@$zone $zone" >> /etc/opendkim/SigningTable
|
echo "*@$zone $zone" >> /etc/opendkim/SigningTable
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
|
@ -50,6 +50,7 @@ fi
|
||||||
cat > /etc/mailinabox.conf << EOF;
|
cat > /etc/mailinabox.conf << EOF;
|
||||||
STORAGE_ROOT=$STORAGE_ROOT
|
STORAGE_ROOT=$STORAGE_ROOT
|
||||||
PUBLIC_HOSTNAME=$PUBLIC_HOSTNAME
|
PUBLIC_HOSTNAME=$PUBLIC_HOSTNAME
|
||||||
|
PUBLIC_IP=$PUBLIC_IP
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Start service configuration.
|
# Start service configuration.
|
||||||
|
|
Loading…
Reference in a new issue