From 6a77f1b9570ebaea4bf2922791a480285f0a1259 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 23 Apr 2014 08:47:48 +0200 Subject: 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/ --- setup-timezone.in | 43 +++++++++++++++++++++++++++++++++++++------ 1 file 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 -- cgit v1.2.3