#!/bin/sh
### BEGIN INIT INFO
# Provides:          univention-demo-configuration
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Should-Start:      named
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: restricted configuration for demo.univention.de
### END INIT INFO
# SPDX-FileCopyrightText: 2012-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only
PATH=/usr/sbin:/usr/bin:/sbin:/bin

case "$1" in
	start|restart|force-reload)
		# make sure listener is running before updating as some join scripts
		# will depend on the listener running ... shut down UMC server during the update
		systemctl stop univention-management-console-server
		ucr set --force \
			listener/autostart=yes \
			umc/server/autostart=no
		systemctl restart univention-directory-listener

		# update system to latest package status
		ucr commit /etc/apt/sources.list.d/*
		while [ -e /var/lock/univention-updater ]
		do
			# make sure that there is no other updater process running (Bug #45070)
			sleep 1
		done
		univention-upgrade --noninteractive
		univention-config-registry set update/reboot/required=false

		# disable the listener after an update to make sure that LDAP changes
		# do not affect the actual system ... re-enable the UMC server
		systemctl stop univention-directory-listener
		ucr set --force listener/autostart=no
		ucr unset --force umc/server/autostart
		systemctl start univention-management-console-server

		# update list of apps
		univention-app update
		;;
	stop|status)
		;;
	*)
		echo "Usage: $0 {start|stop|restart|force-reload|status}"
		exit 1
		;;
esac

exit 0
