ntpdate gets the time and date right on your Puppy
Posted: Mon 07 Aug 2017, 21:26
Hello all.
I've always had a problem with Puppy setting the date and time correctly
for my session. I was setting my time zone correctly, but no luck.
Except with psync, but some Puppies don't have it. And more often than
not, psync is a slowpoke, IMO.
I started searching for an alternative.
At ntp.org, you'll find material to set up your own ntp server if you like,
but there you'll also find a small utility called ntpdate which does exactly
this: set the time on your computer against the data provided by an ntp
server in your country.
~~~~~~~~~
Note --
ntpdate needs the libssl.so.1.1 and libcrypto.so.1.1 to work. Some Pups,
like petihar's Tahr derivative, Triton, do not have it. The following
pinstall.sh script will correct that situation.
Please read the comments in the code below so you won't fall
off your chair if the libs start downloading.
It will also set the country properly in the /etc/ntp.conf file.
This script fetches the dependencies if you don't have them on your Puppy,
and sets the country code for ntpdate according to the second part of your
LANG variable.
The LANG variable syntax is always the pair "language-country" (plus the
utf8 at the end). For ex.: en_US, en_AU, fr_CA, pt_BR. It was easy enough
to extract it for re-use in the ntp.conf file.
I haven't thoroughly checked, but I believe only the smallest countries do
not have their own time server(s). If you live in a country which does not
have a time server, please let me know your country code and I'll try to
incorporate it in the pinstall script. TIA.
At the opposite end, if you live in a large country such as the US, Australia
or Canada, it is not necessary to specify the state or province nearest you:
the ntpdate utility will figure it out through its other configuration file,
ntp.drift, located at /var/lib/ntp. With this, ntpdate can use the ntp server
nearest you, and set your computer date and time faster.
Ntpdate works this way:
based on the country information provided in /etc/ntp.conf, it connects to
the nearest server available in the ntp pool of servers for your country.
(Some countries have dozens, even hundreds, of ntp servers.)
~~~~~~~~~
An advantage of ntpdate is that it will correctly set the date and time on
your computer even if your computer battery is dead! There you go:
musher0 just saved you five bucks!
~~~~~~~~~
Once this pet is installed, please have a look at ~/Startup. You'll see the
ntpdate launcher there is named "zz-ntp-sync.sh". That's on purpose.
This script needs to be the last one called in the Startup chain. I found that
out through experience, I'm not an ntp specialist. Please do not rename
this Startup script.
My tentative explanation is that an ntp connection needs a bit of time to
establish itself properly, and launchers running afterwards would disturb it.
If someone could fill us in with some science on that, it would be great.
~~~~~~~~~
I've been using ntpdate on various recent Puppies (Tahr, Puduan, Slim6,
DPupStretch) for about six months now, and I never had a problem with it.
Your constructive and improvement-oriented feedback is always welcome.
BFN.
I've always had a problem with Puppy setting the date and time correctly
for my session. I was setting my time zone correctly, but no luck.
Except with psync, but some Puppies don't have it. And more often than
not, psync is a slowpoke, IMO.
I started searching for an alternative.
At ntp.org, you'll find material to set up your own ntp server if you like,
but there you'll also find a small utility called ntpdate which does exactly
this: set the time on your computer against the data provided by an ntp
server in your country.
~~~~~~~~~
Note --
ntpdate needs the libssl.so.1.1 and libcrypto.so.1.1 to work. Some Pups,
like petihar's Tahr derivative, Triton, do not have it. The following
pinstall.sh script will correct that situation.
Please read the comments in the code below so you won't fall
off your chair if the libs start downloading.
It will also set the country properly in the /etc/ntp.conf file.
Code: Select all
#!/bin/sh
# pinastall.sh # for ntpdate pet
# What this script does:
# 1) It checks if you have the proper ssl and crypto libraries for ntpdate;
# 2) It sets the ntp server configuration file for your country.
# (c) musher0, Aug. 7 2017. GPL3. Please read:
# https://opensource.org/licenses/GPL-3.0
####
A=/usr/lib/libssl.so.1.1;B=/usr/lib/libcrypto.so.1.1
if [ "`ls $A`" != "$A" -o "`ls $B`" != "$B" ];then
# This part gets and installs the libs if not installed in your Puppy.
cd ~/my-applications
wget http://dl.fedoraproject.org/pub/fedora-secondary/releases/26/Everything/i386/os/Packages/o/openssl-libs-1.1.0f-4.fc26.i686.rpm
# This takes a few seconds.
petget openssl-libs-1.1.0f-4.fc26.i686.rpm
# You may wish to delete this rpm archive when done.
# (This openssl archive also contains the libcrypto library.)
fi
##
CountrY="${LANG:3:2}";CountrY="${CountrY,,}"
if [ "`grep -v $CountrY /etc/ntp.conf`" ];then
# If you are in Canada, you don't need this part, because the default
configuration file already points to Canadian servers.
echo "server 0.$CountrY.pool.ntp.org
server 1.$CountrY.pool.ntp.org
server 2.$CountrY.pool.ntp.org
server 3.$CountrY.pool.ntp.org" > /etc/ntp.conf
fi
## Fin | End ##
and sets the country code for ntpdate according to the second part of your
LANG variable.
The LANG variable syntax is always the pair "language-country" (plus the
utf8 at the end). For ex.: en_US, en_AU, fr_CA, pt_BR. It was easy enough
to extract it for re-use in the ntp.conf file.
I haven't thoroughly checked, but I believe only the smallest countries do
not have their own time server(s). If you live in a country which does not
have a time server, please let me know your country code and I'll try to
incorporate it in the pinstall script. TIA.
At the opposite end, if you live in a large country such as the US, Australia
or Canada, it is not necessary to specify the state or province nearest you:
the ntpdate utility will figure it out through its other configuration file,
ntp.drift, located at /var/lib/ntp. With this, ntpdate can use the ntp server
nearest you, and set your computer date and time faster.
Ntpdate works this way:
based on the country information provided in /etc/ntp.conf, it connects to
the nearest server available in the ntp pool of servers for your country.
(Some countries have dozens, even hundreds, of ntp servers.)
~~~~~~~~~
An advantage of ntpdate is that it will correctly set the date and time on
your computer even if your computer battery is dead! There you go:
musher0 just saved you five bucks!
~~~~~~~~~
Once this pet is installed, please have a look at ~/Startup. You'll see the
ntpdate launcher there is named "zz-ntp-sync.sh". That's on purpose.
This script needs to be the last one called in the Startup chain. I found that
out through experience, I'm not an ntp specialist. Please do not rename
this Startup script.
My tentative explanation is that an ntp connection needs a bit of time to
establish itself properly, and launchers running afterwards would disturb it.
If someone could fill us in with some science on that, it would be great.
~~~~~~~~~
I've been using ntpdate on various recent Puppies (Tahr, Puduan, Slim6,
DPupStretch) for about six months now, and I never had a problem with it.
Your constructive and improvement-oriented feedback is always welcome.
BFN.