#!/bin/bash
# https://docs.software-univention.de/app-tutorial-4.1.html

set -e

VERSION=5

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

eval "$(ucr shell)"
APP_NAME="openproject"

# revert ucs_addServiceToLocalhost
ucs_removeServiceFromLocalhost "${APP_NAME}" "$@"

# check whether this app is still installed elsewhere
if ucs_isServiceUnused "${APP_NAME}" "$@"; then
	udm container/cn remove "$@" --dn \
		"cn=$APP_NAME,cn=custom attributes,cn=univention,$ldap_base"
fi

# revert joinscript_save_current_version - so that the join script
# would run again if the app is reinstalled
joinscript_remove_script_from_status_file "$APP_NAME"
