diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2008-12-07 15:55:55 +0100 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2008-12-07 15:55:55 +0100 |
commit | 7500ef53598f2ee2c128bd9b93d5c94b1aa7b6e9 (patch) | |
tree | adcfb41ad6627ff7b899e66a5de299b5da1d581f /src/core | |
parent | cc258490000e54a1897d7905fe5d642cced5779e (diff) |
refactored/cleanup datetime/timezone stuff
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/libs/lib-ui-interactive.sh | 63 | ||||
-rw-r--r-- | src/core/libs/lib-ui.sh | 28 | ||||
-rw-r--r-- | src/core/procedures/base | 10 | ||||
-rw-r--r-- | src/core/procedures/interactive | 12 |
4 files changed, 58 insertions, 55 deletions
diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index dd3f495..0725644 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -62,45 +62,38 @@ interactive_configure_system() # returns: 1 on failure interactive_set_clock() { - # utc or local? - ask_option no "Is your hardware clock in UTC or local time?" \ - "UTC" " " \ - "local" " " \ - || return 1 - HARDWARECLOCK=$ANSWER_OPTION + # utc or local? + ask_option no "Is your hardware clock in UTC or local time?" "UTC" " " "local" " " || return 1 + HARDWARECLOCK=$ANSWER_OPTION - # timezone? - TIMEZONE=`tzselect` || return 1 + # timezone? + ask_timezone || return 1 + TIMEZONE=$ANSWER_TIMEZONE + # set system clock from hwclock - stolen from rc.sysinit + local HWCLOCK_PARAMS="" + if [ "$HARDWARECLOCK" = "UTC" ] + then + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" + else + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" + fi - # set system clock from hwclock - stolen from rc.sysinit - local HWCLOCK_PARAMS="" - if [ "$HARDWARECLOCK" = "UTC" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" - else - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" - fi - if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then - /bin/rm -f /etc/localtime - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime - fi - /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile - - # display and ask to set date/time - dialog --calendar "Set the date.\nUse <TAB> to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || return 1 - local _date="$(cat $ANSWER)" - dialog --timebox "Set the time.\nUse <TAB> to navigate and up/down to change values." 0 0 2> $ANSWER || return 1 - local _time="$(cat $ANSWER)" - echo "date: $_date time: $_time" >$LOG - - # save the time - # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss - local _datetime="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')" - echo "setting date to: $_datetime" >$LOG - date -s "$_datetime" 2>&1 >$LOG - /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile + if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ] + then + /bin/rm -f /etc/localtime + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + fi + /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile - return 0 + # display and ask to set date/time + ask_datetime + + # save the time + date -s $ANSWER_DATETIME || show_warning "Date/time setting failed" "Something went wrong when doing date -s $ANSWER_DATETIME" + /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile + + return 0 } diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 1ca87d5..9191998 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -137,6 +137,28 @@ ask_checklist () +ask_datetime () +{ + if [ "$var_UI_TYPE" = dia ] + then + # display and ask to set date/time + dialog --calendar "Set the date.\nUse <TAB> to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || return 1 + local _date="$(cat $ANSWER)" # form like: 07/12/2008 + dialog --timebox "Set the time.\nUse <TAB> to navigate and up/down to change values." 0 0 2> $ANSWER || return 1 + local _time="$(cat $ANSWER)" # form like: 15:26:46 + echo "date: $_date time: $_time" >$LOG + + # DD/MM/YYYY hh:mm:ss -> MMDDhhmmYYYY.ss (date default format, set like date $ANSWER_DATETIME) Not enabled because there is no use for it i think. + # ANSWER_DATETIME=$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\2\1\4\5\3\6#g') + # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss ( date string format, set like date -s $ANSWER_DATETIME) + ANSWER_DATETIME="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')" + elif [ "$var_UI_TYPE" = cli ] + ask_string "Enter date [YYYY-MM-DD hh:mm:ss]" + ANSWER_DATETIME=$ANSWER_STRING + fi +} + + # TODO: we should have a wrapper around this function that keeps trying until the user entered a valid numeric?, maybe a wrapper that wraps all functions # ask for a number. # $1 question @@ -191,6 +213,12 @@ ask_string () } +ask_timezone () # TODO: how to do this in dia? +{ + ANSWER_TIMEZONE=`tzselect` +} + + # ask a yes/no question. # $1 question # $2 default answer yes/no (optional) diff --git a/src/core/procedures/base b/src/core/procedures/base index 7af1452..8a586fb 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -62,15 +62,7 @@ worker_runtime_packages () worker_set_clock () { - HARDWARECLOCK=utc - TIMEZONE=`tzselect` - HWCLOCK_PARAMS=" --utc" - if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ] - then - cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime - fi - /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile - #TODO: user must set date/time and store it + interactive_set_clock } diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index 66efaec..ce63bd1 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -1,5 +1,5 @@ #!/bin/sh -depend_procedure core base # esp for auto_{network,locale,fstab} workers +depend_procedure core base # esp for auto_{network,locale,fstab} and set_clock workers # This is a port of the original /arch/setup script. It doesn't use aif phases but uses it's own menu-based flow (phase) control @@ -176,16 +176,6 @@ worker_prepare_disks() } -# set_clock() -# prompts user to set hardware clock and timezone -# -# params: none -set_clock() -{ - interactive_set_clock -} - - worker_select_source () { #TODO: how to handle user going here again? discard previous settings, warn him that he already done it? |