#!/bin/sh -e
#
# Univention Setup
#  timezone change script
#
# SPDX-FileCopyrightText: 2004-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

# shellcheck source=../setup_utils.sh
. /usr/lib/univention-system-setup/scripts/setup_utils.sh

info_header "$0" "$(gettext "Configuring time zones")"

[ "$check_ldap_access" = "1" ] &&
	exit 0

timezone="$(get_profile_var timezone)" ||
	exit 0
[ -n "$timezone" ] ||
	exit 0

[ -e /etc/timezone ] &&
	[ "$(cat /etc/timezone)" = "$timezone" ] &&
	exit 0

rm -f /etc/localtime /etc/timezone
echo "$timezone" >/etc/timezone
install -m644 "/usr/share/zoneinfo/$timezone" /etc/localtime

service stop ntpsec
# shellcheck disable=SC2015
[ -x /usr/sbin/ntpdate-debian ] && /usr/sbin/ntpdate-debian || true
service start ntpsec

exit 0
