#!/bin/sh
#
# Univention Management Console Module
#  unjoin script
#
# SPDX-FileCopyrightText: 2015-2026 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

## joinscript api: bindpwdfile

VERSION=1

. /usr/share/univention-join/joinscripthelper.lib
. /usr/share/univention-lib/ldap.sh

joinscript_init

eval "$(ucr shell)"
if [ "$server_role" = "domaincontroller_master" -o "$server_role" = "domaincontroller_backup" ]; then
	ucs_removeServiceFromLocalhost "univention-self-service-passwordreset-umc" "$@" || die
fi

if ucs_isServiceUnused "univention-self-service-passwordreset-umc" "$@"; then
	udm settings/extended_attribute remove "$@" \
		--dn "cn=UniventionPasswordSelfServiceContactEmail,cn=custom attributes,cn=univention,$ldap_base"
	udm settings/extended_attribute remove "$@" \
		--dn "cn=UniventionPasswordSelfServiceContactMobile,cn=custom attributes,cn=univention,$ldap_base"
	udm policies/umc modify "$@" \
		--dn "cn=selfservice-umc-servers,cn=UMC,cn=policies,$ldap_base" \
		--remove "allow=cn=passwordreset-all,cn=operations,cn=UMC,cn=univention,$ldap_base"
	udm settings/umc_operationset remove "$@" \
		--dn "cn=passwordreset-all,cn=operations,cn=UMC,cn=univention,$ldap_base"
fi

joinscript_remove_script_from_status_file univention-self-service-passwordreset-umc

exit 0
