#!/bin/bash
#Clock Set Gui 
#Robert Lane 2009 2010(tasmod)
# 27.02.11 rodin.s i18n

AFRICA="africa.pool.ntp.org"
ASIA="asia.pool.ntp.org" 
EUROPE="europe.pool.ntp.org" 
NORTHAMERICA="north-america.pool.ntp.org " 
SOUTHAMERICA="south-america.pool.ntp.org " 
OCEANIA="oceania.pool.ntp.org" 
UK="uk.pool.ntp.org" 

BLURB="# Psync autorun server location - Rob Lane (tasmod) 2010"

case "$1" in
AFRICA)
Xdialog --infobox "$(gettext 'Setting Time ........Please wait')" 12 40 &
           ntpdate  $AFRICA > /tmp/settertime
           hwclock -w
NEWCURRENT_TIME=`date +%c`
offset=`cat /tmp/settertime | grep 'offset' | cut -d 't' -f 6,7`
echo -e $BLURB  > /usr/local/psync/setcountry
echo -e "AFRICAREP" >> /usr/local/psync/setcountry
;;
ASIA)
Xdialog --infobox "$(gettext 'Setting Time ........Please wait')" 12 40 &
          ntpdate $ASIA > /tmp/settertime
	      hwclock -w
NEWCURRENT_TIME=`date +%c`
offset=`cat /tmp/settertime | grep 'offset' | cut -d 't' -f 6,7`
echo -e $BLURB  > /usr/local/psync/setcountry
echo -e "ASIAREP" >> /usr/local/psync/setcountry
;;
EUROPE)
Xdialog --infobox "$(gettext 'Setting Time ........Please wait')" 12 40 &
         ntpdate $EUROPE > /tmp/settertime
         hwclock -w
NEWCURRENT_TIME=`date +%c`
offset=`cat /tmp/settertime | grep 'offset' | cut -d 't' -f 6,7`
echo -e $BLURB  > /usr/local/psync/setcountry
echo -e"EUROPEREP" >> /usr/local/psync/setcountry
;;
NORTHAMERICA)
Xdialog --infobox "$(gettext 'Setting Time ........Please wait')" 12 40 &
         ntpdate  $NORTHAMERICA > /tmp/settertime
         hwclock -w
NEWCURRENT_TIME=`date +%c`
offset=`cat /tmp/settertime | grep 'offset' | cut -d 't' -f 6,7`
echo -e $BLURB  > /usr/local/psync/setcountry
echo -e "NORTHAMERICAREP" >> /usr/local/psync/setcountry
;;
SOUTHAMERICA)
Xdialog --infobox "$(gettext 'Setting Time ........Please wait')" 12 40 &
         ntpdate  $SOUTHAMERICA > /tmp/settertime
	     hwclock -w
NEWCURRENT_TIME=`date +%c`
offset=`cat /tmp/settertime | grep 'offset' | cut -d 't' -f 6,7`
echo -e $BLURB  > /usr/local/psync/setcountry
echo -e "SOUTHAMERICAREP" >> /usr/local/psync/setcountry
;;
OCEANIA)
Xdialog --infobox "$(gettext 'Setting Time ........Please wait')" 12 40 &
        ntpdate $OCEANIA > /tmp/settertime
    	hwclock -w
NEWCURRENT_TIME=`date +%c`
offset=`cat /tmp/settertime | grep 'offset' | cut -d 't' -f 6,7`
echo -e $BLURB  > /usr/local/psync/setcountry
echo -e "OCEANIAREP" >> /usr/local/psync/setcountry
;;
UK)
Xdialog --infobox "$(gettext 'Setting Time ........Please wait')" 12 40 &
         ntpdate  $UK > /tmp/settertime
		 hwclock -w   
NEWCURRENT_TIME=`date +%c`
offset=`cat /tmp/settertime |grep 'offset' | cut -d 't' -f 6,7`
echo -e $BLURB  > /usr/local/psync/setcountry
echo -e "UKREP" >> /usr/local/psync/setcountry
;;

################################################################
#Autostart case select to run server pool country with no report
#Exit command prevents GUI running
################################################################

AFRICAREP)
           ntpdate  $AFRICA > /tmp/settertime
           hwclock -w
exit
;;

ASIAREP)
          ntpdate $ASIA > /tmp/settertime
	      hwclock -w
exit
;;

EUROPEREP)
         ntpdate $EUROPE > /tmp/settertime
         hwclock -w
exit
;;

NORTHAMERICAREP)
         ntpdate  $NORTHAMERICA > /tmp/settertime
         hwclock -w
exit
;;

SOUTHAMERICAREP)
         ntpdate  $SOUTHAMERICA > /tmp/settertime
	     hwclock -w
exit
;;

OCEANIAREP)
        ntpdate $OCEANIA > /tmp/settertime
    	hwclock -w
exit
;;

UKREP)
         ntpdate  $UK > /tmp/settertime
		 hwclock -w   
exit
;;
esac


   	
cd $HOME
export timeis="
<window title=\"$(gettext 'Synchronised Time')\">
    <vbox>
    <frame $(gettext 'Updated Time')>
   	<text use-markup=\"true\"><label>\"<b>$NEWCURRENT_TIME</b>\"</label></text>
	<text><label>\"       \"</label></text>
	<text use-markup=\"true\"><label>\" <b>  $(gettext 'Offset was') $offset      </b>\"</label></text>
	</frame>
    <frame>
    <text><label> $(gettext 'To synchronise your clock at each startup.') </label></text>
    <text><label>$(gettext 'Press the button for auto run at each startup.')</label></text>
    <text><label>\"       \"</label></text>
    <hbox>
	<button>
    <input file icon=\"gtk-execute\"></input>
    <label>$(gettext 'Autostart')</label>
    <action>cp /usr/local/psync/timesync.sh  /root/Startup/timesync.sh</action>
    <action> exit: gtkdialogue </action>
    </button>
    <button>
    <input file icon=\"gtk-execute\"></input>
    <label>$(gettext 'Remove Autostart')</label>
    <action>rm /root/Startup/timesync.sh</action>
    <action> exit: gtkdialogue </action>
    </button>
    <button>
    <input file icon=\"gtk-close\"></input>
    <label>$(gettext 'Close')</label>
    </button>
    </hbox>
    </frame>
    </vbox>
</window>"

#execute gtkdialog
gtkdialog3 -c -p  timeis 



