9983023a0835627d8277c5721445aa27d1c32ab2
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_datetime.sh
1 #!/bin/sh
2
3 # Set the timezone and date/time
4
5 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
6
7
8 case $mainsel in
9
10   "tz")
11
12     while ! area=$(zenity --list --title "Select your time zone" --text="Please select your area" --column="Select your area" --print-column=1 "Africa" "America" "Asia" "Australia" "Europe" "Pacific" --width=500 --height=260) || [ "x$area" = "x" ] ; do
13           zenity --title="Error" --error --text="Please select your area." --timeout=6
14     done
15
16     while ! timezone=$(ls -1 /usr/share/zoneinfo/$area | zenity ---width=500 --height=200 --title="Select your closest location" --list --column "Closest Location" --text "Please select the location closest to you") || [ "x$timezone" = "x" ] ; do
17            zenity --title="Error" --error --text="Please select your location." --timeout=6
18     done
19
20     echo $timezone
21     rm /etc/localtime && ln -s /usr/share/zoneinfo/$area/$timezone /etc/localtime
22   ;;
23
24   "td")
25
26   #Make sure we clean up any leading zeros in the day (as Zenity freaks out)
27   date_d=`date +%d | sed 's/^0//'`
28   date_m=`date +%m | sed 's/^0//'`
29   date_y=`date +%Y`
30
31   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
32           zenity --title="Error" --error --text="Please select the date." --timeout 6
33   done
34
35   echo $date
36
37   time_h=`date +%H`
38   time_m=`date +%M`
39
40   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
41           zenity --title="Error" --error --text="Please input the time." --timeout 6
42   done
43
44   while ! date -d $time ; do
45           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")
46   done
47   date +%Y%m%d -s $date
48   date +%H:%M -s $time
49   ;;
50
51 esac
52 done