From 3c9483c433ec200a8cb35cb978ae4d9e9c994f3c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 7 May 2011 23:19:17 +0200 Subject: bugfix: deal correctly with /etc/localtime. Fixes FS#24119 * always execute copy_timezone_file (), whether the user changed the timezone or not, and no matter which procedure we're running. (specifically automatic procedure!) if $TIMEZONE is set, it will create /etc/localtime appropriately on the live system * make target_localtime () - executed through postconfigure_target () - compatible with the case where no /etc/localtime file exists. --- src/core/libs/lib-misc.sh | 8 ++++++++ src/core/libs/lib-ui-interactive.sh | 23 ++++++++++++++++------- src/core/procedures/automatic | 4 ++-- src/core/procedures/base | 4 +++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index 2dee841..f9fd06a 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -165,6 +165,14 @@ target_configure_time () { ${var_TARGET_DIR}/etc/rc.conf } +target_localtime () { + if [ -f /etc/localtime ] + then + cp /etc/localtime ${var_TARGET_DIR}/etc/localtime || return 1 + fi + return 0 +} + # apped string after last line matching regex in a file. # $1 regex # $2 string (can contain "\n", "\t" etc) diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 1600cef..05dd234 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -44,7 +44,7 @@ postconfigure_target () { local failed=() target_run_mkinitcpio || failed+=('mkinitcpio creation') target_locale-gen || failed+=('locale generation') - cp /etc/localtime ${var_TARGET_DIR}/etc/localtime || failed+=('localtime copying') + target_localtime || failed+=('localtime copying') [ ${#failed[@]} -gt 0 ] && warn_failed 'Postconfigure' "${failed[@]}" && return 1 return 0 } @@ -122,14 +122,23 @@ interactive_configure_system() interactive_timezone () { ask_timezone || return 1 TIMEZONE=$ANSWER_TIMEZONE - inform "Setting Timezone to $TIMEZONE" - if [ -n "$TIMEZONE" -a -e "/usr/share/zoneinfo/$TIMEZONE" ] + return 0 +} + +# this should be executed, whether the user changed $TIMEZONE or not +copy_timezone_file () { + if [ -z "$TIMEZONE" ] then - # This changes probably also the systemtime (UTC->$TIMEZONE)! - # localtime users will have a false time after that! - /bin/rm -f /etc/localtime || return 1 - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime || return 1 + debug UI-INTERACTIVE "\$TIMEZONE is empty, not creating/updating /etc/localtime" + return 0 fi + debug UI-INTERACTIVE "Setting Timezone to $TIMEZONE" + local file="/usr/share/zoneinfo/$TIMEZONE" + [ -e "$file" ] || die_error "No such timezone file: $file, did you choose a non-existing timezone?" + # This changes probably also the systemtime (UTC->$TIMEZONE)! + # localtime users will have a false time after that! + /bin/rm -f /etc/localtime || return 1 + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime || return 1 return 0 } diff --git a/src/core/procedures/automatic b/src/core/procedures/automatic index 407a35b..ce773e1 100644 --- a/src/core/procedures/automatic +++ b/src/core/procedures/automatic @@ -102,8 +102,8 @@ worker_install_packages () worker_set_clock () { - #TODO implement this - true + # uses $TIMEZONE, clock itself remains untouched. + copy_timezone_file } diff --git a/src/core/procedures/base b/src/core/procedures/base index 4e41c81..dba70d1 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -105,13 +105,14 @@ worker_runtime_packages () worker_set_clock () { local default=no + local timezone_file_copied=0 while true; do ask_option $default "Date/time configuration" '' required \ "1" "Select region and timezone" \ "2" "Set time and date" \ "3" "Return to Main Menu" || return 1 case $ANSWER_OPTION in - "1") execute worker interactive_timezone && default=2 || return 1 ;; + "1") execute worker interactive_timezone && copy_timezone_file && timezone_file_copied=1 && default=2 || return 1 ;; "2") if check_depend worker interactive_timezone then execute worker interactive_time && default=3 || return 1 @@ -119,6 +120,7 @@ worker_set_clock () "3") break ;; esac done + [ $timezone_file_copied -eq 1 ] || copy_timezone_file || return 1 return 0 } -- cgit v1.2.3