Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 20 Oct 2014, 04:43
All times are UTC - 4
 Forum index » House Training » Bugs ( Submit bugs )
Puppy 528 time sync bugs and fix
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
Moose On The Loose


Joined: 24 Feb 2011
Posts: 528

PostPosted: Fri 14 Jun 2013, 10:39    Post subject:  Puppy 528 time sync bugs and fix
Subject description: The script that did the time sync on boot had several problems
 

I tried to do it as an attachment but I got "extension not allowed" error messages when I tried.

I commented what the script does and added some GUI to tell the user about the issues.

In the older version, if the network was not working at the time of boot, the sync function would silently fail.

In this version, a simple GUIis forced on if there is an error so the user knows what to do rather than scratching their head about why the time is wrong any time they re-boot.

If the "localtime" "utc" thing had a commented line in it, the script would silently fail.




****** Cut here ************
#!/bin/bash
#Clock Set Gui
# /usr/local/psync/psyncfunc
# This used the:
#Robert Lane 2009 2010 2011(tasmod)
# version as a starting point
#
# Many edits by moose-on-the-loose, to the point of a near complete
# rewrite but with care to keep compatible with the existing
# timesync.sh script

# List the servers that will be used
# If you are adding one remember
# 1-The variable name must be the same as what comes in on $1
# 2-If it is not ntp.org an edit is needed later in this script
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"

# Turn the $1 into the DOGUI switch and server name
WHERE="${1}"
WHERE="${1/%REP/,false}"
WHERE="${WHERE},true"
DOGUI=$(echo "$WHERE" | cut -d "," -f 2 )
WHERE=$(echo "$WHERE" | cut -d "," -f 1 )
eval "SERVER=\${${WHERE}}"


# if something weird happened stuff in a default value for now
if ! ( echo "$SERVER" | grep -q "ntp.org" ) ; then
SERVER="$NORTHAMERICA"
DOGUI="true"
Xdialog -infobox "Trouble in /usr/local/psync/psyncfunc the server name
looks incorrect setting it to a default of $SERVER" 0 0
fi

# Read the /etc/clock file to look at what sort of time we are doing
# it is "localtime" or "utc"
#
# This doesn't work if there are comments in the file
#HTIME=`cat /etc/clock | grep 'HWCLOCKTIME' | cut -d "=" -f 2 `
# This fixes that
HTIME=$( cat /etc/clock | cut -d "#" -f 1 | grep "HWCLOCKTIME" | cut -d "=" -f 2 )

# If I don't find the file etc, I force it to UTC.
if [[ "$HTIME" == "localtime" ]] ; then
HWCLOCKCMD="hwclock -w"
else
# all else taken as UTC
HWCLOCKCMD="hwclock --systohc --utc"
if [[ "$HTIME" != "utc" ]] ; then
Xdialog -infobox "Trouble in /usr/local/psync/psyncfunc the read of
/etc/clock gave something other than 'localtime' or 'utc'" 0 0
fi
fi


# A loop so we can check again after we think it is fixed
while (true) ; do
# Any network "link" that is "BROADCAST" and "UP" is assumed to be a
# working network
if ! ( ip link | grep "<BROADCAST" | grep -q ",UP," ) ; then
DOGUI="true"
TEXT="<text xalign=\"0\" wrap=\"true\" width-request=\"500\"><label>"
TEND="</label></text>"
MSG="$TEXT We are attempting to sychronize the clock to an external"
MSG="$MSG server but there is no network working yet."
MSG="$MSG You have a few options for trying to fix this. $TEND"
TEXT="<text xalign=\"0\" wrap=\"true\" width-request=\"400\"><label>"
OP1="$TEXT It may be that the network connection took time to start working"
OP1="$OP1 and by time you have read this is now running. $TEND"
OP2="$TEXT The network may not be configured. Click here to run the"
OP2="$OP2 network wizard. $TEND"
OP3="$TEXT If you want to deal with the problem manually, click here."
OP3="$OP3 The clock synchroization will not be done at this time $TEND"
BUTTON="<button width-request=\"100\"><label>"
BEND="</label></button></hbox></frame>"
export P="
<window title=\"Synchronised Time problem\"><vbox><frame>$MSG</frame>
<frame><hbox>$OP1 $BUTTON Retry $BEND
<frame><hbox>$OP2 $BUTTON Connect $BEND
<frame><hbox>$OP3 $BUTTON Quit $BEND
</vbox>
</window>"
RESULT=$(gtkdialog3 -c -p P)
RESULT=${RESULT/*=/}
RESULT=${RESULT//\"/}
RESULT=${RESULT// /}
case $RESULT in
Retry)
continue
;;
Connect)
/usr/local/apps/Connect/AppRun
;;
* )
exit
;;
esac
else
break
fi
done


if $DOGUI ; then
Xdialog --infobox "Setting Time ........Please wait" 12 40 &
fi

OFFSET=$(ntpdate $SERVER | grep "offset")
OFFSET="${OFFSET/*offset/}"

BLURB="# Psync autorun server location - Rob Lane (tasmod) 2011 (mod KS)"

echo -e $BLURB > /usr/local/psync/setcountry
echo -e "${WHERE}REP" >> /usr/local/psync/setcountry


if ! $DOGUI ; then
exit
fi


cd $HOME
export timeis="
<window title=\"Synchronised System Time\">
<vbox>
<frame Updated Time>
<text use-markup=\"true\"><label>\"<b>$NEWCURRENT_TIME</b>\"</label></text>
<text><label>\" \"</label></text>
<text use-markup=\"true\"><label>\" <b> Offset was $OFFSET </b>\"</label></text>
</frame>
<frame>
<text><label> To synchronise your clock at each startup. </label></text>
<text><label>Press the button for auto run at each startup.</label></text>
<text><label>\" \"</label></text>
<hbox>
<button>
<input file icon=\"gtk-execute\"></input>
<label>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>Remove Autostart</label>
<action>rm /root/Startup/timesync.sh</action>
<action> exit: gtkdialogue </action>
</button>
<button>
<input file icon=\"gtk-close\"></input>
<label>Close</label>
</button>
</hbox>
</frame>
</vbox>
</window>"

#execute gtkdialog
gtkdialog3 -c -p timeis
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Bugs ( Submit bugs )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0613s ][ Queries: 11 (0.0118s) ][ GZIP on ]