Root/
Source at commit 5ca385580fb612a5e63de82d4fe8e6d71ad9a852 created 12 years 6 months ago. By Warren Pattison, Minor Changes. | |
---|---|
1 | #!/bin/sh |
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=`date +%Z` |
50 | |
51 | # Is timezone right? |
52 | |
53 | dialog --backtitle "$BACKTITLE" --yesno "Timezone is: "$TZ" \nIs this correct?" 0 0 |
54 | if [ "$?" != "0" ]; then |
55 | ## No? Fetch, Then set it and reboot |
56 | ## dialog |
57 | ## Set the Timezone |
58 | ## uci set system.@system[0].timezone=$TIMEZONE |
59 | ## uci commit system |
60 | |
61 | ## Tell the User we need to reboot |
62 | ## dialog --backtitle "$BACKTITLE" -- |
63 | exit 1 |
64 | fi |
65 | |
66 | # Get the Date |
67 | |
68 | dialog --backtitle "$BACKTITLE" --calendar "Set the date" 0 0 2>/tmp/time |
69 | |
70 | # Exit if user chose to cancel |
71 | if [ "$?" != "0" ]; then |
72 | exit 1 |
73 | fi |
74 | |
75 | # Get the Time |
76 | |
77 | dialog --backtitle "$BACKTITLE" --timebox "Set the time" 0 0 2>>/tmp/time |
78 | |
79 | # Exit if user chose to cancel |
80 | if [ "$?" != "0" ]; then |
81 | exit 1 |
82 | fi |
83 | |
84 | # Format the input |
85 | |
86 | DAY=`cut -s -f1 -d '/' /tmp/time` |
87 | MONTH=`cut -s -f2 -d '/' /tmp/time` |
88 | YEAR=`cut -s -f3 -d '/' /tmp/time` |
89 | HOURS=`cut -s -f1 -d ':' /tmp/time` |
90 | MINUTES=`cut -s -f2 -d ':' /tmp/time` |
91 | |
92 | SET=$YEAR$MONTH$DAY$HOURS$MINUTES |
93 | |
94 | echo $SET |
95 | |
96 | |
97 | # Set and apply to internal clock |
98 | |
99 | date $SET |
100 | hwclock --systohc --utc |
101 | dialog --backtitle "$BACKTITLE" --infobox "The time and date have now been\nset and saved.\n\nenjoy" 0 0 |
102 | |
103 | |
104 | # Clean Up |
105 | |
106 | rm /tmp/time |
107 | |
108 |
Branches:
master