#!/bin/sh PREFIX= . "$PREFIX/lib/libalpine.sh" zroot=/usr/share/zoneinfo 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 ) } valid_tz() { find $zroot -type f -a -not -name '*.tab' -a -not -name 'Factory' \ | xargs posixtz | sort | uniq | grep -q -w "$1" } if ! apk info -q -e tzdata; then apk add -q tzdata && apkdel="tzdata" || exit 1 fi zonepath=$(cat /etc/TZ 2>/dev/null) [ -z "$zonepath" ] && zonepath="UTC" while true; do echo -n "What 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 local 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 TZ= if valid_tz "$zonepath"; then TZ="$zonepath" elif [ -f "$zroot/$zonepath" ]; then TZ=$(posixtz "$zroot/$zonepath") \ || echo "Failed to convert '$zroot/$zonepath' to POSIX TZ" fi if [ -n "$TZ" ]; then echo $TZ > /etc/TZ || rm -f /etc/TZ break fi echo "'$zonepath' is not a vaild timezone on this system" done if [ -n "$apkdel" ]; then apk del -q $apkdel fi