Root/
Source at commit ac84168269f754c560d231d13ba0849862628fe7 created 12 years 26 days ago. By Freemor, ben-time-set.sh finally close to done.. needs real world Added Tweaks dir - modified /etc/profile - New /etc/banner with ben name and Qi logo | |
---|---|
1 | #!/bin/bash |
2 | # |
3 | # Script to facilitate setting the |
4 | # date and time on the Ben NanoNote |
5 | # Copyright 2011 by Warren "Freemor" Pattison |
6 | # |
7 | # This program is free software: you can redistribute it and/or modify |
8 | # it under the terms of the GNU General Public License as published by |
9 | # the Free Software Foundation, either version 3 of the License, or |
10 | # (at your option) any later version. |
11 | # |
12 | # This program is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | # GNU General Public License for more details. |
16 | # |
17 | # You should have received a copy of the GNU General Public License |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | |
20 | # First we set up a few things |
21 | |
22 | VERSION="0.0.5" |
23 | BACKTITLE="Ben NanoNote Time/Date Utility" |
24 | TIMEZONE="" |
25 | #DATEFORMAT="%Y%m%d" |
26 | #TIMEFORMAT="%H%M" |
27 | setfont /usr/share/kbd/consolefonts/kernel-6x11-font # size down the font so the Calendar widget fits. |
28 | |
29 | # Check For the dialog program |
30 | |
31 | if [ ! -e /usr/bin/dialog ]; then |
32 | echo "We need the dialog program to do this nicely." |
33 | echo "please install it with:" |
34 | echo "opkg install dialog" |
35 | echo |
36 | echo "and try again..." |
37 | exit 1 |
38 | fi |
39 | |
40 | # Intro and Instructions |
41 | |
42 | dialog --backtitle "$BACKTITLE" --cr-wrap --trim --msgbox "Use this utility to set the time, date\n\ |
43 | and timezone on your NanoNote.\n\n\ |
44 | Use the TAB key to move between fields.\n\ |
45 | use the directional pad to set the value.\n" 0 0 |
46 | |
47 | # Set Timezone first as that requires a reboot |
48 | |
49 | TZ=`cat /etc/TZ` |
50 | |
51 | # Is timezone right? |
52 | |
53 | dialog --backtitle "$BACKTITLE" --yesno "Timezone is: "$TZ" \nIs this correct?" 0 0 |
54 | |
55 | if [ "$?" != "0" ]; then |
56 | dialog --backtitle "$BACKTITLE" --menu "Select your Region:" 0 0 8 Africa "" America "" Antarctica "" Arctic "" Asia "" Atlantic "" Australia "" Europe "" Indian "" Pacific "" 2>/tmp/result |
57 | ZONES=( $(grep -i $(</tmp/result) timezones | cut -f2- -d/) ) |
58 | dialog --backtitle "$BACKTITLE" --menu "Select the nearest City:" 0 0 8 `for ITEM in $(seq 0 $((${#ZONES[@]} - 1))); do echo ${ZONES[$ITEM]#*|} ${ZONES[$ITEM]%|*}; done` 2>/tmp/result |
59 | TIMEZONE=$(</tmp/result) |
60 | #echo $TIMEZONE |
61 | #exit 1 |
62 | #Commit Timezone string to firmware |
63 | uci set system.@system[0].timezone="$TIMEZONE" |
64 | uci commit system |
65 | #Clean-up |
66 | rm /tmp/result |
67 | #ASK to reboot... (Pet peeve.. never reboot by default) |
68 | dialog --backtitle "$BACKTITLE" --yesno "Timezone has been set\nSystem will now restart so Linux can adjust.\n\n Reboot?" 0 0 |
69 | if [ "$?" == 0 ]; then |
70 | reboot |
71 | exit 0 |
72 | else |
73 | exit 0 |
74 | fi |
75 | fi |
76 | |
77 | |
78 | # Get the Date |
79 | |
80 | dialog --backtitle "$BACKTITLE" --calendar "Set the date" 0 0 2>/tmp/time |
81 | |
82 | # Exit if user chose to cancel |
83 | if [ "$?" != "0" ]; then |
84 | exit 1 |
85 | fi |
86 | |
87 | # Get the Time |
88 | |
89 | dialog --backtitle "$BACKTITLE" --timebox "Set the time" 0 0 2>>/tmp/time |
90 | |
91 | # Exit if user chose to cancel |
92 | if [ "$?" != "0" ]; then |
93 | exit 1 |
94 | fi |
95 | |
96 | # Format the input |
97 | |
98 | DAY=`cut -s -f1 -d '/' /tmp/time` |
99 | MONTH=`cut -s -f2 -d '/' /tmp/time` |
100 | YEAR=`cut -s -f3 -d '/' /tmp/time` |
101 | HOURS=`cut -s -f1 -d ':' /tmp/time` |
102 | MINUTES=`cut -s -f2 -d ':' /tmp/time` |
103 | |
104 | SET=$YEAR$MONTH$DAY$HOURS$MINUTES |
105 | |
106 | echo $SET |
107 | |
108 | |
109 | # Set and apply to internal clock |
110 | |
111 | date $SET |
112 | hwclock --systohc --utc |
113 | dialog --backtitle "$BACKTITLE" --infobox "The time and date have now been\nset and saved.\n\nenjoy" 0 0 |
114 | |
115 | |
116 | # Clean Up |
117 | |
118 | rm /tmp/time |
119 | |
120 |
Branches:
master