#!/bin/bash # # 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 . # First we set up a few things VERSION="0.1.2" BACKTITLE="Ben NanoNote Time/Date Utility" TIMEZONE="" TZFILE="/usr/share/ben-time-set/timezones" NOTZ=0 #DATEFORMAT="%Y%m%d" #TIMEFORMAT="%H%M" setfont /usr/share/kbd/consolefonts/kernel-6x11-font # size down the font so the Calendar widget fits. # 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 # Check that we have a timezones file if [ ! -e /usr/share/ben-time-set/timezones ]; then if [ -e ./timezones ]; then TZFILE="./timezones" else echo "oops.. no timezones file" echo "We will be unable to set the Timezone." echo "If you want to be able to set the timezone" echo "Please download the timezones file and save" echo "it to the same folder as the script or" echo "/usr/share/ben-time-set/" echo "--" read -p "Press a key to continue" -n1 -s NOTZ=1 fi fi echo $TZFILE, $NOTZ #exit 0 # 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 if [ $NOTZ == 0 ]; then TZ=`cat /etc/TZ` # Is timezone right? dialog --backtitle "$BACKTITLE" --yesno "Timezone is: "$TZ" \nIs this correct?" 0 0 if [ "$?" != "0" ]; then dialog --backtitle "$BACKTITLE" --menu "Select your Region:" 0 0 8 Africa "" America "" Antarctica "" Arctic "" Asia "" Atlantic "" Australia "" Europe "" Indian "" Pacific "" 2>/tmp/result if [ "$?" != "0" ]; then exit 1 fi ZONES=( $(grep -i $(/tmp/result if [ "$?" != "0" ]; then exit 1 fi TIMEZONE=$(/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