Root/ben-time-set/ben-time-set.sh

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
22VERSION="0.0.5"
23BACKTITLE="Ben NanoNote Time/Date Utility"
24TIMEZONE=""
25#DATEFORMAT="%Y%m%d"
26#TIMEFORMAT="%H%M"
27setfont /usr/share/kbd/consolefonts/kernel-6x11-font # size down the font so the Calendar widget fits.
28
29# Check For the dialog program
30
31if [ ! -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
38fi
39
40# Intro and Instructions
41
42dialog --backtitle "$BACKTITLE" --cr-wrap --trim --msgbox "Use this utility to set the time, date\n\
43and timezone on your NanoNote.\n\n\
44Use the TAB key to move between fields.\n\
45use the directional pad to set the value.\n" 0 0
46
47# Set Timezone first as that requires a reboot
48
49TZ=`cat /etc/TZ`
50
51# Is timezone right?
52
53dialog --backtitle "$BACKTITLE" --yesno "Timezone is: "$TZ" \nIs this correct?" 0 0
54
55if [ "$?" != "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
75fi
76
77
78# Get the Date
79
80dialog --backtitle "$BACKTITLE" --calendar "Set the date" 0 0 2>/tmp/time
81
82# Exit if user chose to cancel
83if [ "$?" != "0" ]; then
84   exit 1
85fi
86
87# Get the Time
88
89dialog --backtitle "$BACKTITLE" --timebox "Set the time" 0 0 2>>/tmp/time
90
91# Exit if user chose to cancel
92if [ "$?" != "0" ]; then
93   exit 1
94fi
95
96# Format the input
97
98DAY=`cut -s -f1 -d '/' /tmp/time`
99MONTH=`cut -s -f2 -d '/' /tmp/time`
100YEAR=`cut -s -f3 -d '/' /tmp/time`
101HOURS=`cut -s -f1 -d ':' /tmp/time`
102MINUTES=`cut -s -f2 -d ':' /tmp/time`
103
104SET=$YEAR$MONTH$DAY$HOURS$MINUTES
105
106echo $SET
107
108
109# Set and apply to internal clock
110
111date $SET
112hwclock --systohc --utc
113dialog --backtitle "$BACKTITLE" --infobox "The time and date have now been\nset and saved.\n\nenjoy" 0 0
114
115
116# Clean Up
117
118rm /tmp/time
119
120

Archive Download this file

Branches:
master



interactive