#!/bin/sh
#
# Univention Self Service
#  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

ucs_removeServiceFromLocalhost "univention-self-service" "$@" || die

if ucs_isServiceUnused "univention-self-service" "$@"
then
	eval "$(ucr shell)"
	udm policies/umc modify "$@" \
		--dn "cn=selfservice-umc-servers,cn=UMC,cn=policies,$ldap_base" \
		--remove "allow=cn=passwordchange-all,cn=operations,cn=UMC,cn=univention,$ldap_base"
	udm container/cn modify "$@" \
		--dn "cn=dc,cn=computers,$ldap_base" \
		--policy-dereference "cn=selfservice-umc-servers,cn=UMC,cn=policies,$ldap_base"
	udm container/cn modify "$@" \
		--dn "cn=memberserver,cn=computers,$ldap_base" \
		--policy-dereference "cn=selfservice-umc-servers,cn=UMC,cn=policies,$ldap_base"
	udm policies/umc remove "$@" \
		--dn "cn=selfservice-umc-servers,cn=UMC,cn=policies,$ldap_base"
fi

joinscript_remove_script_from_status_file univention-self-service

exit 0
