#!/bin/sh
#
# Univention Setup
#  nameserver change script
#
# SPDX-FileCopyrightText: 2004-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

# shellcheck source=../setup_utils.sh
. /usr/lib/univention-system-setup/scripts/setup_utils.sh

info_header "$0" "$(gettext "Setting name server")"

[ "$check_ldap_access" = "1" ] &&
	exit 0

oldvalues=""
newvalues=""

for name in nameserver1 nameserver2 nameserver3
do
	var="$(get_profile_var "$name")" ||
		continue

	oldvalues="$oldvalues#$(univention-config-registry get "$name")"
	newvalues="$newvalues#$var"
	if [ -z "$var" ]; then
		univention-config-registry unset "$name"
	else
		univention-config-registry set "$name=$var"
	fi
done

if [ -d "/var/lib/univention-system-setup/nameserver.post" ]; then
	run-parts /var/lib/univention-system-setup/nameserver.post --arg="$oldvalues" --arg="$newvalues"
fi

exit 0
