#!/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.0.5" BACKTITLE="Ben NanoNote Time/Date Utility" TIMEZONE="" #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 # 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=`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 ZONES=( $(grep -i $(/tmp/result 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