Puppy 528 time sync bugs and fix

Please post any bugs you have found
Post Reply
Message
Author
User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

Puppy 528 time sync bugs and fix

#1 Post by Moose On The Loose »

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

Post Reply