#!/bin/bash
#
# Univention System Activation
#
# SPDX-FileCopyrightText: 2015-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

function has_activated_license {
	/usr/bin/univention-ldapsearch -LLL '(&(objectClass=univentionLicense)(univentionLicenseKeyID=*))' dn | grep -q 'dn:'
}

role="$(ucr get server/role)"
if [ "$role" == "domaincontroller_master" ]; then
	/usr/sbin/univention-system-activation start
elif has_activated_license; then
	# Installing an App Appliance as Non-Primary Directory Node without activated license in the domain
	# is restricted by system-setup and not handled here

	# lift root restrictions set by univention-system-activation.postinst on Non-Primary Directory Node
	# roles because system-activation is not started there
	/usr/sbin/univention-system-activation allow-root
fi
exit 0
