#!/bin/bash

phase="$1"
version="$2"
school_version="ucsschool_20240924121830"

if [ "x$phase" = "xpost" ] && [ "x$version" = "x5.1-0" ]; then
	if [ "${server_role:-}" = "domaincontroller_master" ]; then
		echo "Checking for existing UCS@school join hook..."
		DN="$(udm settings/data list --filter ucsversionend=5.99-0 --filter filename=ucsschool-join-hook.py | sed -nre 's/^DN: //p')"
		if [ -z "$DN" ] ; then
			echo "Update validity period for existing UCS@school join hook..."
			udm settings/data modify --dn "$DN" --set ucsversionend=5.0-99
			echo "UCS@school join hook has been updated. Validity ends with UCS 5.0-99."
		fi
	fi
fi

exit 0
