# Set the timezone and date/time
-while mainsel=$(zenity --title="Date / Time / Timezone" --width="400" --height="250" --list --column "id" --column "Please select" --hide-column=1 --text="You can set the time and date or select a different timezone.\n" "td" "Change Time and Date" "tz" "Select Timezone" --ok-label="Change Setting" --cancel-label="Exit"); do
+while mainsel=$(zenity --title="Date / Time / Timezone" --width="400" --height="250" --list --column "id" --column "Please select" --hide-column=1 --text="You can set the time and date or select a different timezone.\n" "td" "Change Time and Date" "tz" "Select Timezone" "sync" "Sync time over Internet" "autosync" "Sync on network connection" --ok-label="Change Setting" --cancel-label="Exit"); do
case $mainsel in
echo $timezone
rm /etc/localtime && ln -s /usr/share/zoneinfo/$area/$timezone /etc/localtime
+ echo "$area/$timezone" > /etc/timezone
;;
"td")
date_m=`date +%m | sed 's/^0//'`
date_y=`date +%Y`
- while ! date=$(zenity --calendar --text="Please select the current date" --title "Please select the current date" --day=$date_d --month=$date_m --year=$date_y --date-format="%Y%m%d" --width=500) || [ "x$date" = "x" ] ; do
- zenity --title="Error" --error --text="Please select the date." --timeout 6
+ date=""
+ while [ "x$date" = "x" ] ; do
+ date=$(zenity --calendar --text="Please select the current date" --title "Please select the current date" --day=$date_d --month=$date_m --year=$date_y --date-format="%Y%m%d" --width=500) || exit 1
done
echo $date
time_h=`date +%H`
time_m=`date +%M`
- while ! time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM).\n\nThe screen might blank out after you changed the time.\nDon't panic. Simply press a button on the keyboard.\n" --entry-text "$time_h:$time_m") || [ "x$time" = "x" ] ; do
- zenity --title="Error" --error --text="Please input the time." --timeout 6
+ while true; do
+ time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM).\n" --entry-text "$time_h:$time_m") || exit 1
+ if test -n "$time" && date -d "$time"; then
+ break;
+ fi
+ zenity --title="Error" --error --text="Please input the time." --timeout 6
done
- while ! date -d $time ; do
- time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM).\n\nThe screen might blank out after you changed the time.\nDon't panic. Simply press a button on the keyboard.\n" --entry-text "$time_h:$time_m")
- done
+ # take care of screensaver first
+ screensaver_enabled=true
+ if xset q | grep -A2 'Screen Saver' | grep -q 'timeout:.*\<0\>.*cycle'; then
+ screensaver_enabled=false
+ fi
+ xset s off
+
date +%Y%m%d -s $date
date +%H:%M -s $time
- ;;
+ hwclock -u -w
+ if $screensaver_enabled; then
+ xset s on
+ fi
+ ;;
+ "sync")
+ screensaver_enabled=true
+ if xset q | grep -A2 'Screen Saver' | grep -q 'timeout:.*\<0\>.*cycle'; then
+ screensaver_enabled=false
+ fi
+ xset s off
+ (
+ test -e /etc/init.d/ntpd && sudo /etc/init.d/ntpd stop
+ sudo ntpdate pool.ntp.org
+ ) |
+ zenity --progress \
+ --title="Syncing..." \
+ --text="Syncing with time server...\nPlease wait a while..." \
+ --pulsate
+ test -e /etc/init.d/ntpd && sudo /etc/init.d/ntpd start
+ if $screensaver_enabled; then
+ xset s on
+ fi
+ ;;
+ "autosync")
+ if zenity --question --title="Autosync time" --text="The Pandora can automatically sync the time whenever you connect to a network.\n\nShould it do that?" --ok-label="Yes" --cancel-label="No"; then
+ chmod +x /etc/NetworkManager/dispatcher.d/ntpdate.sh
+ else
+ chmod -x /etc/NetworkManager/dispatcher.d/ntpdate.sh
+ fi
+ ;;
esac
-done
\ No newline at end of file
+done