1
0
mirror of git://projects.qi-hardware.com/nanobits.git synced 2024-11-27 15:55:56 +02:00
nanobits/ben-time-set/ben-time-set.sh
2011-09-03 13:44:59 -03:00

107 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
#
# Script to facilitate setting the
# date and time on the Ben NanoNote
# Copyright 2011 by Warren "Freemor" Pattison
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# First we set up a few things
VERSION="0.0.5"
BACKTITLE="Ben NanoNote Time/Date Utility"
TIMEZONE=""
#DATEFORMAT="%Y%m%d"
#TIMEFORMAT="%H%M"
# Check For the dialog program
if [ ! -e /usr/bin/dialog ]; then
echo "We need the dialog program to do this nicely."
echo "please install it with:"
echo "opkg install dialog"
echo
echo "and try again..."
exit 1
fi
# Intro and Instructions
dialog --backtitle "$BACKTITLE" --cr-wrap --trim --msgbox "Use this utility to set the time, date\n\
and timezone on your NanoNote.\n\n\
Use the TAB key to move between fields.\n\
use the directional pad to set the value.\n" 0 0
# Set Timezone first as that requires a reboot
TZ=`date +%Z`
# Is timezone right?
dialog --backtitle "$BACKTITLE" --yesno "Timezone is: "$TZ" \nIs this correct?" 0 0
if [ "$?" != "0" ]; then
## No? Fetch, Then set it and reboot
## dialog
## Set the Timezone
## uci set system.@system[0].timezone=$TIMEZONE
## uci commit system
## Tell the User we need to reboot
## dialog --backtitle "$BACKTITLE" --
exit 1
fi
# Get the Date
dialog --backtitle "$BACKTITLE" --calendar "Set the date" 0 0 2>/tmp/time
# Exit if user chose to cancel
if [ "$?" != "0" ]; then
exit 1
fi
# Get the Time
dialog --backtitle "$BACKTITLE" --timebox "Set the time" 0 0 2>>/tmp/time
# Exit if user chose to cancel
if [ "$?" != "0" ]; then
exit 1
fi
# Format the input
DAY=`cut -s -f1 -d '/' /tmp/time`
MONTH=`cut -s -f2 -d '/' /tmp/time`
YEAR=`cut -s -f3 -d '/' /tmp/time`
HOURS=`cut -s -f1 -d ':' /tmp/time`
MINUTES=`cut -s -f2 -d ':' /tmp/time`
SET=$YEAR$MONTH$DAY$HOURS$MINUTES
echo $SET
# Set and apply to internal clock
date $SET
hwclock --systohc --utc
dialog --backtitle "$BACKTITLE" --infobox "The time and date have now been\nset and saved.\n\nenjoy" 0 0
# Clean Up
rm /tmp/time