summaryrefslogtreecommitdiffstats
path: root/dhcpcd/dhcpcd-hooks/15-timezone
blob: 23ae924c5afe055e5618924a834e6853af491e6a (plain) (blame)
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
# Configure timezone

: ${localtime:=/etc/localtime}

set_zoneinfo()
{
	local zoneinfo_dir= zone_file=

	[ -z "$new_tzdb_timezone" ] && return 0

	for d in \
		/usr/share/zoneinfo	\
		/usr/lib/zoneinfo	\
		/var/share/zoneinfo	\
		/var/zoneinfo		\
	; do
		if [ -d "$d" ]; then
			zoneinfo_dir="$d"
			break
		fi
	done

	if [ -z "$zoneinfo_dir" ]; then
		syslog warning "timezone directory not found"
		return 1
	fi

	zone_file="$zoneinfo_dir/$new_tzdb_timezone"
	if [ ! -e "$zone_file" ]; then
		syslog warning "no timezone definition for $new_tzdb_timezone"
		return 1
	fi

	syslog info "timezone changed to $new_tzdb_timezone"
	if [ -h "$localtime" ]; then
		ln -sf "$zone_file" "$localtime"
	else
		cp "$zone_file" "$localtime"
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_tzdb_timezone="$new_dhcp6_tzdb_timezone"
	;;
esac

if $if_up; then
 	set_zoneinfo
fi