diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-time.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-time.sh index 3d73f7c..bc3a166 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-time.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-set-time.sh @@ -1,5 +1,8 @@ #!/bin/bash -export NCURSES_NO_UTF8_ACS=1 # prevents weirdness over tty +# prevents weirdness over tty +export NCURSES_NO_UTF8_ACS=1 +export TERM=xterm-256color +export LANG=C.UTF-8 if [[ $EUID -ne 0 ]]; then echo -e "This script must be run as root. Try \`sudo femto-set-timezone\`." @@ -12,6 +15,7 @@ help=$(cat </dev/null 2>&1; then + if hwclock --systohc >/dev/null 2>&1; then + rtc="New time successfully saved to RTC.\n" + else + rtc="Unable to communicate with RTC module. An RTC module can save system time between reboots/power outages.\n" + fi + echo "System time updated to:\n$(date)\n\n${rtc}Time & date are also set automatically from internet." + return 0 + else + echo "Failed to set system time." + return 1 + fi +} + + +while getopts ":t:T:h" opt; do case ${opt} in t) # Option -t (timezone) set_timezone "$OPTARG" ;; + T) # Option -t (timestamp) + set_timestamp "$OPTARG" + ;; h) # Option -h (help) echo -e "$help" ;; esac done -# Fetch available time zones -echo "Loading timezones..." -timezones=$(timedatectl list-timezones) -# Build the options array -options=() -while IFS= read -r timezone; do - options+=("$timezone" "x") -done <<< "$timezones" +if [ $arg_count -eq 0 ]; then # if the script was launched with no arguments, then load the UI. + # Fetch available time zones + echo "Loading timezones..." + timezones=$(timedatectl list-timezones) + # Build the options array + options=() + while IFS= read -r timezone; do + options+=("$timezone" "x") + done <<< "$timezones" -# Convert options array to string -options_str=$(printf '%s\n' "${options[@]}") + # Convert options array to string + options_str=$(printf '%s\n' "${options[@]}") -# Show timezone selection menu with preselection of current timezone -selected_timezone=$(dialog --title "Select Timezone" \ - --default-item "$(cat /etc/timezone)" \ - --menu "Current timezone: $(cat /etc/timezone) (UTC$(date +%z))" 20 60 10 \ - $(printf "%s " "${options[@]}") 3>&1 1>&2 2>&3) -exit_status=$? -if [[ $exit_status -eq 0 && -n "$selected_timezone" ]]; then - # Set the selected time zone - set_timezone $selected_timezone -else - exit 1 -fi - -DATE=$(echo "$(dialog --title "Select Date" --calendar "Choose a date:\nCurrent date: $(date "+%B %d, %Y")\nPress [TAB] to select." 0 0 $(date +%d) $(date +%m) $(date +%Y) 3>&1 1>&2 2>&3)" | awk -F/ '{printf "%04d-%02d-%02d", $3, $2, $1}') -if [ $? -eq 1 ]; then #if cancel/no - exit 1 -fi -TIME=$(dialog --title "Set Time" --timebox "Select time:\nCurrent time: $(date +%H:%M:%S)\nPress [TAB] to select." 0 0 3>&1 1>&2 2>&3) # Dialog timebox for time -if [ $? -eq 1 ]; then #if cancel/no - exit 1 -fi -if date -s "$DATE $TIME"; then # set time - if hwclock --systohc; then - rtc="New time successfully saved to RTC." + # Show timezone selection menu with preselection of current timezone + selected_timezone=$(dialog --title "Select Timezone" \ + --default-item "$(cat /etc/timezone)" \ + --menu "Current timezone: $(cat /etc/timezone) (UTC$(date +%z))" 20 60 10 \ + $(printf "%s " "${options[@]}") 3>&1 1>&2 2>&3) + exit_status=$? + if [[ $exit_status -eq 0 && -n "$selected_timezone" ]]; then + # Set the selected time zone + set_timezone $selected_timezone else - rtc="Unable to communicate with RTC module. An RTC module can save system time between reboots/power outages." + exit 1 fi - log_message "System time updated to:\n$(date)\n\n$rtc\nTime & date are also set automatically from internet." -else - log_message "Failed to set system time." - exit 1 + + DATE=$(echo "$(dialog --title "Select Date" --calendar "Choose a date:\nCurrent date: $(date "+%B %d, %Y")\nPress [TAB] to select." 0 0 $(date +%d) $(date +%m) $(date +%Y) 3>&1 1>&2 2>&3)" | awk -F/ '{printf "%04d-%02d-%02d", $3, $2, $1}') + if [ $? -eq 1 ]; then #if cancel/no + exit 1 + fi + TIME=$(dialog --title "Set Time" --timebox "Select time:\nCurrent time: $(date +%H:%M:%S)\nPress [TAB] to select." 0 0 3>&1 1>&2 2>&3) # Dialog timebox for time + if [ $? -eq 1 ]; then #if cancel/no + exit 1 + fi + + log_message "$(set_timestamp $(date -d "$DATE $TIME" +%s))" + exit $? #exit status matches set_timestamp exit status + fi \ No newline at end of file