#!/bin/bash
#
# Univention Self Service
# register an ACL file
#
# SPDX-FileCopyrightText: 2019-2026 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

ACTION="$1"
ACL_FILENAME="$2"
ACL_VERSION="$3"

if [ "$#" -ne 3 ]; then
	echo "usage: univention-self-service-register-acl register|unregister ACL_FILENAME ACL_VERSION"
	exit 1
fi

if ! [ "$ACTION" = "register" -o "$ACTION" = "unregister" ]; then
	echo "first parameter must be 'register' or 'unregister'"
	exit 1
fi

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

if [ "$ACTION" = "register" ]; then
	ucs_registerLDAPExtension \
	--packagename univention-self-service \
	--packageversion "$ACL_VERSION" \
	--ucsversionstart "5.2-5" --ucsversionend "5.99-0" \
	--acl "$ACL_FILENAME" 2>&1
else
	ACL_BASENAME="$(basename $ACL_FILENAME)"
	ACL_NAME=${ACL_BASENAME%".acl"}
	ucs_unregisterLDAPExtension --acl "$ACL_NAME" 2>&1
fi
