#!/bin/bash
#
# Univention Self Service
#  postinst file for the debian package
#
# SPDX-FileCopyrightText: 2019-2026 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

#DEBHELPER#

systemctl try-restart univention-directory-listener


if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 7.1.0~; then
    if (ucr get self-service/ldap_attributes | grep -qE '(^st,|,st,|st$)' && ! ucr get self-service/ldap_attributes | grep -qE '(^c,|,c,|c$)'); then
        ucr set self-service/ldap_attributes="$(ucr get self-service/ldap_attributes),c"
    fi
fi
if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 5.0.1-19~; then
	/usr/share/univention-self-service/univention-setup-self-service-portal-links
	udm portals/entry modify \
		--dn "cn=self-service,cn=entry,cn=portals,cn=univention,$(ucr get ldap/base)" \
		--set activated=FALSE
fi

exit 0
