File: tzdata.postinst

package info (click to toggle)
tzdata 2025c-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,152 kB
  • sloc: awk: 1,369; makefile: 797; python: 780; sh: 451
file content (78 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/sh
set -e

LC_ALL=C
LANG=C
unset TZ
umask 022

get_timezone() {
	if ! [ -L "$DPKG_ROOT/etc/localtime" ] ; then
		return
	fi
	timezone="$(readlink "$DPKG_ROOT/etc/localtime")"
	timezone="$(cd "$DPKG_ROOT/etc" && realpath -m -s "$timezone")"
	echo "${timezone#/usr/share/zoneinfo/}"
}

remove_etc_timezone() {
	if [ -e "$DPKG_ROOT/etc/timezone" ] ; then
		echo "Removing now unused /etc/timezone."
		rm -f "$DPKG_ROOT/etc/timezone"
	fi
}

. /usr/share/debconf/confmodule
db_version 2.0

if [ "$1" = configure ]; then
	# Get the values from debconf
	AREA=Etc
	ZONE=UTC
	db_get tzdata/Areas && AREA="$RET"
	db_get "tzdata/Zones/$AREA" && ZONE="$RET"
	TIMEZONE="$AREA/$ZONE"
	db_stop

	# Update the time zone
	if test "$(get_timezone)" != "$TIMEZONE"; then
		ln -nsf "/usr/share/zoneinfo/$TIMEZONE" "$DPKG_ROOT/etc/localtime.dpkg-new" && \
			mv -f "$DPKG_ROOT/etc/localtime.dpkg-new" "$DPKG_ROOT/etc/localtime"
		which restorecon >/dev/null 2>&1 && restorecon "$DPKG_ROOT/etc/localtime"
	fi

	echo
	echo "Current default time zone: '$TIMEZONE'"

	# Show the new setting to the user
	UTdate=$(LC_ALL=C TZ=UTC0 date)
	TZdate=$(unset TZ ; LANG=C date -d "$UTdate")
	echo "Local time is now:      $TZdate."
	echo "Universal Time is now:  $UTdate."
	if [ -z "$DEBCONF_RECONFIGURE" ] ; then
		echo "Run 'dpkg-reconfigure tzdata' if you wish to change it."
	fi
	echo

	# Remove /etc/timezone:
	# - on upgrade from Debian trixie or older
	# - on upgrade from Ubuntu 25.10 "questing" and older
	# - on upgrade from tzdata (<< 2025c-2) starting with forky
	case "$2" in
	*+deb1[0-3]u*)
		remove_etc_timezone
		;;
	*-0ubuntu0.2[0-5]*)
		remove_etc_timezone
		;;
	*)
		if dpkg --compare-versions "$2" lt "2025c-2" ; then
			remove_etc_timezone
		fi
		;;
	esac
fi

#DEBHELPER#

exit 0