add support for multiple domains in docker deployment

This commit is contained in:
Benjamin Bärthlein 2020-04-27 21:21:27 +02:00
parent 0993b7fdcb
commit 3dee004b2d
3 changed files with 20 additions and 17 deletions

View File

@ -5,7 +5,7 @@ services:
restart: always
environment:
DDNS_ADMIN_LOGIN: 'admin:$$3$$abcdefg'
DDNS_DOMAIN: 'dyndns.example.com'
DDNS_DOMAINS: 'dyndns.example.com'
DDNS_PARENT_NS: 'ns.example.com'
DDNS_DEFAULT_TTL: '3600'
ports:

View File

@ -1,4 +1,4 @@
DDNS_ADMIN_LOGIN=admin:$$3$$abcdefg
DDNS_DOMAIN=dyndns.example.com
DDNS_DOMAINS=dyndns.example.com
DDNS_PARENT_NS=ns.example.com
DDNS_DEFAULT_TTL=3600

View File

@ -1,19 +1,21 @@
#!/bin/bash
[ -z "$DDNS_ADMIN_LOGIN" ] && echo "DDNS_ADMIN_LOGIN not set" && exit 1;
[ -z "$DDNS_DOMAIN" ] && echo "DDNS_DOMAIN not set" && exit 1;
[ -z "$DDNS_DOMAINS" ] && echo "DDNS_DOMAINS not set" && exit 1;
[ -z "$DDNS_PARENT_NS" ] && echo "DDNS_PARENT_NS not set" && exit 1;
[ -z "$DDNS_DEFAULT_TTL" ] && echo "DDNS_DEFAULT_TTL not set" && exit 1;
DDNS_IP=$(curl icanhazip.com)
if ! grep 'zone "'$DDNS_DOMAIN'"' /etc/bind/named.conf > /dev/null
for d in ${DDNS_DOMAINS//,/ }
do
if ! grep 'zone "'$d'"' /etc/bind/named.conf > /dev/null
then
echo "creating zone...";
cat >> /etc/bind/named.conf <<EOF
zone "$DDNS_DOMAIN" {
zone "$d" {
type master;
file "$DDNS_DOMAIN.zone";
file "$d.zone";
allow-query { any; };
allow-transfer { none; };
allow-update { localhost; };
@ -21,13 +23,13 @@ zone "$DDNS_DOMAIN" {
EOF
fi
if [ ! -f /var/cache/bind/$DDNS_DOMAIN.zone ]
if [ ! -f /var/cache/bind/$d.zone ]
then
echo "creating zone file..."
cat > /var/cache/bind/$DDNS_DOMAIN.zone <<EOF
cat > /var/cache/bind/$d.zone <<EOF
\$ORIGIN .
\$TTL 86400 ; 1 day
$DDNS_DOMAIN IN SOA ${DDNS_PARENT_NS}. root.${DDNS_DOMAIN}. (
$d IN SOA ${DDNS_PARENT_NS}. root.${d}. (
74 ; serial
3600 ; refresh (1 hour)
900 ; retry (15 minutes)
@ -36,10 +38,11 @@ $DDNS_DOMAIN IN SOA ${DDNS_PARENT_NS}. root.${DDNS_DOMAIN}. (
)
NS ${DDNS_PARENT_NS}.
A ${DDNS_IP}
\$ORIGIN ${DDNS_DOMAIN}.
\$ORIGIN ${d}.
\$TTL ${DDNS_DEFAULT_TTL}
EOF
fi
done
# If /var/cache/bind is a volume, permissions are probably not ok
chown root:bind /var/cache/bind