blob: 1d76c80fc1b61620e4e98af7b9d6e19153e134c3 (
plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#!/bin/sh
PREFIX=
. "$PREFIX/lib/libalpine.sh"
zroot=/usr/share/zoneinfo
usage() {
cat <<__EOF__
usage: setup-timezone [-h] [-z subdir of $zroot]
Sets the timezone for the system.
options:
-h Show this help
-z Specify the timezone as a subdirectory of $zroot
__EOF__
exit 1
}
show_tz_list() {
local i z= list=
local path="$zroot/$1"
[ -d "$path" ] || return 1
for i in $(find $path -maxdepth 1); do
case $i in
*.tab|*/) continue;;
esac
if [ -d "$i" ]; then
z="$z ${i##*/}/"
else
z="$z ${i##*/}"
fi
done
( cd $path && ls --color=never -Cd $z )
}
setup_tz() {
mkdir -p "${ROOT}"etc/zoneinfo
cp "$1" "${ROOT}"etc/zoneinfo/localtime
}
while getopts "hz:" opt; do
case $opt in
h) usage;;
z) ZONEINFODIR="$OPTARG";;
esac
done
if ! apk info --quiet --installed tzdata; then
apk add --quiet tzdata && apkdel="tzdata" || exit 1
fi
zonepath=UTC
while true; do
if [ -n "$ZONEINFODIR" ]; then
setup_tz "$ZONEINFODIR"
break
fi
echo -n "Which timezone are you in? ('?' for list) [$zonepath] "
default_read zonepath "$zonepath"
case "$zonepath" in
"") continue;;
"?") show_tz_list; continue;;
esac
while [ -d "$zroot/$zonepath" ]; do
zone=
echo -n "What sub-timezone of '$zonepath' are you in? ('?' for list) "
default_read zone
case "$zone" in
"?") show_tz_list "$zonepath"; continue;;
esac
zonepath="$zonepath/$zone"
done
if [ -f "$zroot/$zonepath" ]; then
setup_tz "$zroot/$zonepath"
break
fi
echo "'$zonepath' is not a valid timezone on this system"
done
if [ -n "$apkdel" ]; then
apk del --quiet $apkdel
fi
|