diff options
author | Jeff Bilyk <jbilyk@gmail.com> | 2011-08-05 22:35:31 -0400 |
---|---|---|
committer | Jeff Bilyk <jbilyk@gmail.com> | 2011-08-05 22:35:31 -0400 |
commit | 3587c1daa2578e7054ece6153e2c8e86741533d0 (patch) | |
tree | 88c85ce89e675875f2a553e1cfd1fc7106a4d193 /setup-timezone.in | |
parent | 5e4f30db6bc90e55460a29f1f862ed73830d0727 (diff) | |
download | alpine-conf-3587c1daa2578e7054ece6153e2c8e86741533d0.zip |
setup-timezone: command line options for posixtz format and tzdata format
Diffstat (limited to 'setup-timezone.in')
-rwxr-xr-x | setup-timezone.in | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/setup-timezone.in b/setup-timezone.in index 3d45284..54b96c3 100755 --- a/setup-timezone.in +++ b/setup-timezone.in @@ -6,6 +6,20 @@ PREFIX= zroot=/usr/share/zoneinfo +usage() { + cat <<__EOF__ +usage: setup-timezone [-h] [-p posixtz format] [-z subfolder of $zroot] + +Sets the timezone for the system. + +options: + -h Show this help + -p Specify the timezone in PosixTZ format + -z Specify the timezone as a subfolder of $zroot +__EOF__ + exit 1 +} + show_tz_list() { local i z= list= local path="$zroot/$1" @@ -29,6 +43,14 @@ valid_tz() { | xargs posixtz | sort | uniq | grep -q -w "$1" } +while getopts "hp:z:" opt; do + case $opt in + h) usage;; + p) POSIXTZ="$OPTARG";; + t) ZONEINFOFOLDER="$OPTARG";; + esac +done + if ! apk info -q -e tzdata; then apk add -q tzdata && apkdel="tzdata" || exit 1 fi @@ -37,6 +59,19 @@ zonepath=$(cat /etc/TZ 2>/dev/null) [ -z "$zonepath" ] && zonepath="UTC" while true; do + if [ -n "$POSIXTZ" ]; then + echo $POSIXTZ > /etc/TZ || rm -f /etc/TZ + break + fi + + if [ -n "$ZONEINFOFOLDER" ]; then + TZ=$(posixtz "$ZONEINFOFOLDER") || echo "Failed to convert '$ZONEINFOFOLDER' to POSIX TZ" + if [ -n "$TZ" ]; then + echo $TZ > /etc/TZ || rm -f /etc/TZ + fi + break + fi + echo -n "Which timezone are you in? ('?' for list) [$zonepath] " default_read zonepath "$zonepath" case "$zonepath" in |