#!/bin/bash
# Copyright 2017 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

set -e

# Copy the bind config from /etc.
mkdir -p $SNAP_DATA/bind/
cp -f $SNAP/etc/bind/* $SNAP_DATA/bind/

# Overwrite named.conf from the one shipped with the snap.
cp -f $SNAP/usr/share/maas/bind/named.conf $SNAP_DATA/bind/

# Ensure the cache directory exists.
mkdir -p $SNAP_DATA/bind/cache

# MAAS finalize bind configuration.
MAAS_DNS_CONFIG_DIR="$SNAP_DATA/bind" $SNAP/bin/maas-rack setup-dns

# Run named.
exec $SNAP/usr/sbin/named -c "$SNAP_DATA/bind/named.conf" -g
