summaryrefslogtreecommitdiff
path: root/setup-timezone.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2014-04-23 08:47:48 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2014-04-23 11:34:25 +0200
commit6a77f1b9570ebaea4bf2922791a480285f0a1259 (patch)
treeba6c2e27c3ee6edc94a783aefc3eef4c1aa1d5e0 /setup-timezone.in
parent81ae21f658b6ddb4b34e03f44b20a196d8eb18cf (diff)
downloadalpine-conf-6a77f1b9570ebaea4bf2922791a480285f0a1259.zip
setup-timezone: refactor. -i for install all tzdata and -k for keep copies
By default we copy the tzdata file to /etc/zoneinfo and symlink to our copy. We also purge all previously copied timezones unless -k is given. If -i is specified, then will the tzdata apk package stay and the symlink will point to /usr/share/zoneinfo/... instead of a copy in /etc/zoneinfo/
Diffstat (limited to 'setup-timezone.in')
-rwxr-xr-xsetup-timezone.in43
1 files changed, 37 insertions, 6 deletions
diff --git a/setup-timezone.in b/setup-timezone.in
index 1d76c80..9220e03 100755
--- a/setup-timezone.in
+++ b/setup-timezone.in
@@ -8,12 +8,14 @@ zroot=/usr/share/zoneinfo
usage() {
cat <<__EOF__
-usage: setup-timezone [-h] [-z subdir of $zroot]
+usage: setup-timezone [-h] [-k|-i] [-z subdir of $zroot]
Sets the timezone for the system.
options:
-h Show this help
+ -i Install tzdata and symlink instead of making a copy
+ -k Keep previous copies of tzdata
-z Specify the timezone as a subdirectory of $zroot
__EOF__
exit 1
@@ -38,22 +40,51 @@ show_tz_list() {
}
setup_tz() {
+ local zonepath="$1"
mkdir -p "${ROOT}"etc/zoneinfo
- cp "$1" "${ROOT}"etc/zoneinfo/localtime
+ if ! $INSTALL_TZDATA; then
+ local zone="${zonepath#*/zoneinfo/}"
+ local zdir="${zonepath%/*}"/
+ zdir="${zdir#*/zoneinfo/}"
+ if ! $KEEP_TZDATA; then
+ rm -r "${ROOT}"/etc/zoneinfo
+ fi
+ mkdir -p "${ROOT}"etc/zoneinfo/$zdir
+ cp "$zonepath" "${ROOT}"etc/zoneinfo/$zdir/
+ zonepath=/etc/zoneinfo/$zone
+ fi
+ rm -f "${ROOT}"etc/zoneinfo/localtime
+ ln -s "$zonepath" "${ROOT}"etc/zoneinfo/localtime
}
-while getopts "hz:" opt; do
+INSTALL_TZDATA=false
+KEEP_TZDATA=false
+while getopts "hikz:" opt; do
case $opt in
h) usage;;
+ i) INSTALL_TZDATA=true;;
+ k) KEEP_TZDATA=true;;
z) ZONEINFODIR="$OPTARG";;
esac
done
-if ! apk info --quiet --installed tzdata; then
- apk add --quiet tzdata && apkdel="tzdata" || exit 1
+if $INSTALL_TZDATA; then
+ pkg=tzdata
+ apkdel=
+else
+ pkg="--virtual .setup-timezone tzdata"
+ apkdel=".setup-timezone"
+fi
+
+apk add --quiet $pkg
+
+if [ -L "${ROOT}"etc/zoneinfo/localtime ]; then
+ zonepath=$(readlink "${ROOT}"etc/zoneinfo/localtime)
+ zonepath=${zonepath#*/zoneinfo/}
+else
+ zonepath=UTC
fi
-zonepath=UTC
while true; do
if [ -n "$ZONEINFODIR" ]; then