#!/bin/sh
#
# Copyright 2001-2014 Univention GmbH
#
# http://www.univention.de/
#
# All rights reserved.
#
# The source code of this program is made available
# under the terms of the GNU Affero General Public License version 3
# (GNU AGPL V3) as published by the Free Software Foundation.
#
# Binary versions of this program provided by Univention to you as
# well as other copyrighted, protected or trademarked materials like
# Logos, graphics, fonts, specific documentations and configurations,
# cryptographic keys etc. are subject to a license agreement between
# you and Univention and not subject to the GNU AGPL V3.
#
# In the case you use this program under the terms of the GNU AGPL V3,
# the program is provided in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License with the Debian GNU/Linux or Univention distribution in file
# /usr/share/common-licenses/AGPL-3; if not, see
# <http://www.gnu.org/licenses/>.

@%@UCRWARNING=# @%@

if [ "$(uname -m)" = "x86_64" ]; then
	export LDB_MODULES_PATH=/usr/lib/x86_64-linux-gnu/ldb/
else
	export LDB_MODULES_PATH=/usr/lib/i386-linux-gnu/ldb/
fi

# dirs under /var/run can go away on reboots.
mkdir -p /var/run/named
chmod 775 /var/run/named

# bind is running as root when using s4 as backend.
# To open the rndc port, the rndc.key must be owned by root.
chown root:root /etc/bind/rndc.key
chown root:bind /var/run/named >/dev/null 2>&1 || true

PATH=/sbin:/bin:/usr/sbin:/usr/bin

debug_level="$(ucr get dns/debug/level)"
test -z $debug_level && debug_level=0

OPTS="-c /etc/bind/named.conf.samba4 -f -d $debug_level"

exec /usr/sbin/named $OPTS
