xref: /dragonfly/contrib/dhcpcd/hooks/15-timezone (revision c9c5aa9e)
1# Configure timezone
2
3: ${localtime:=/etc/localtime}
4
5set_zoneinfo()
6{
7	[ -z "$new_tzdb_timezone" ] && return 0
8
9	zoneinfo_dir=
10	for d in \
11		/usr/share/zoneinfo	\
12		/usr/lib/zoneinfo	\
13		/var/share/zoneinfo	\
14		/var/zoneinfo		\
15	; do
16		if [ -d "$d" ]; then
17			zoneinfo_dir="$d"
18			break
19		fi
20	done
21
22	if [ -z "$zoneinfo_dir" ]; then
23		syslog warning "timezone directory not found"
24		return 1
25	fi
26
27	zone_file="$zoneinfo_dir/$new_tzdb_timezone"
28	if [ ! -e "$zone_file" ]; then
29		syslog warning "no timezone definition for $new_tzdb_timezone"
30		return 1
31	fi
32
33	if copy_file "$zone_file" "$localtime"; then
34		syslog info "timezone changed to $new_tzdb_timezone"
35	fi
36}
37
38# For ease of use, map DHCP6 names onto our DHCP4 names
39case "$reason" in
40BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
41	new_tzdb_timezone="$new_dhcp6_tzdb_timezone"
42	;;
43esac
44
45if $if_configured && $if_up; then
46 	set_zoneinfo
47fi
48