diff options
author | Simon Rettberg | 2017-11-27 15:15:30 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-27 15:15:30 +0100 |
commit | a9e496a02d5eb2d30bf819374317657869cff007 (patch) | |
tree | 728d71d4cd39a56044ff48d4a26d6cfc79ff6fa6 /core/rootfs/rootfs-stage31 | |
parent | [hardware-stats] Import SLX vars in standby-script (diff) | |
download | mltk-a9e496a02d5eb2d30bf819374317657869cff007.tar.gz mltk-a9e496a02d5eb2d30bf819374317657869cff007.tar.xz mltk-a9e496a02d5eb2d30bf819374317657869cff007.zip |
[rfs-stage31] Honor NTP servers returned by DHCP for timesync; fallback to $SLX_NOW
Diffstat (limited to 'core/rootfs/rootfs-stage31')
4 files changed, 46 insertions, 15 deletions
diff --git a/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig b/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig index 0ce6bfae..79596646 100644 --- a/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig +++ b/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig @@ -17,6 +17,7 @@ fetch_text_config() { echo "# Config fetched from $URL" >> "$CONFIG" echo "#_RCONFIG_TAG" >> "$CONFIG" + CONFIG_DOWNLOAD_TIME=$(sed -r 's/^([0-9]+)\.([0-9]+).*$/\1\2/' /proc/uptime) cat "${CONFIG}-remote" >> "$CONFIG" } ######################################################################### diff --git a/core/rootfs/rootfs-stage31/data/inc/ntp_sync b/core/rootfs/rootfs-stage31/data/inc/ntp_sync index 940af366..b5344e5f 100755 --- a/core/rootfs/rootfs-stage31/data/inc/ntp_sync +++ b/core/rootfs/rootfs-stage31/data/inc/ntp_sync @@ -1,22 +1,49 @@ +#!/bin/ash # Sync time via network func_sync_net_time() { - local SERVER - if [ -n "$SLX_NTP_SERVER" ]; then - for SERVER in $SLX_NTP_SERVER; do - if ntpdate -u -p 2 "$SERVER"; then - echo "Successfully queried $SERVER for time." - if [ "x$SLX_BIOS_CLOCK" = "xlocal" ]; then - usleep 100000 - hwclock -l -w || echo "... but could not set BIOS clock to localtime" - elif [ "x$SLX_BIOS_CLOCK" = "xutc" ]; then - usleep 100000 - hwclock -u -w || echo "... but could not set BIOS clock to UTC" + local SERVER SUCCESS NTPSRV + # Try to merge with servers from DHCP. Prefer DHCP, skip duplicates + touch /run/ntpsrv + for SERVER in $SLX_NTP_SERVER; do + if ! grep -Fxq "$SERVER" /run/ntpsrv; then + echo "$SERVER" >> /run/ntpsrv + fi + done + fi + NTPSRV=$(cat /run/ntpsrv) + SUCCESS= + for SERVER in $NTPSRV; do + if ntpdate -u -p 2 "$SERVER"; then + echo "Successfully queried $SERVER for time." + if [ "x$SLX_BIOS_CLOCK" = "xlocal" ]; then + usleep 100000 + hwclock -l -w || echo "... but could not set BIOS clock to localtime" + elif [ "x$SLX_BIOS_CLOCK" = "xutc" ]; then + usleep 100000 + hwclock -u -w || echo "... but could not set BIOS clock to UTC" + fi + SUCCESS=1 + break + fi + echo "Error querying $SERVER for current time." + done + if [ -z "$SUCCESS" ]; then + echo "No NTP server reachable" + # See if we have a timestamp in our server-config - should only be a few seconds off by now + if [ -n "$SLX_NOW" ] && [ "$SLX_NOW" -gt 1234567890 ]; then + TTS="$SLX_NOW" + if [ -n "$CONFIG_DOWNLOAD_TIME" ]; then + NOW_TIME=$(sed -r 's/^([0-9]+)\.([0-9]+).*$/\1\2/' /proc/uptime) + if [ "$CONFIG_DOWNLOAD_TIME" -gt 0 ] && [ "$NOW_TIME" -gt 0 ]; then + TTS=$(( TTS + ( NOW_TIME - CONFIG_DOWNLOAD_TIME ) / 100 )) fi - break fi - echo "Error querying $SERVER for current time." - done + echo "Setting time to SLX_NOW ($SLX_NOW, corrected $TTS)" + date -s "@$TTS" + else + echo "No fallback option for timesync available, relying on correct RTC setup" + fi fi } diff --git a/core/rootfs/rootfs-stage31/data/inc/setup_network b/core/rootfs/rootfs-stage31/data/inc/setup_network index 1440e3ef..897469cc 100644 --- a/core/rootfs/rootfs-stage31/data/inc/setup_network +++ b/core/rootfs/rootfs-stage31/data/inc/setup_network @@ -104,5 +104,5 @@ echo "CLIENTIP=$CLIENTIP" >> /run/network.conf echo "GATEWAY=$GATEWAY" >> /run/network.conf echo "BRIDGE=$BRIDGE" >> /run/network.conf -udhcpc $PARAM -O domain -O nissrv -O nisdomain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" +udhcpc $PARAM -O ntpsrv -O domain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" # udhcpc return value will be return value of this script diff --git a/core/rootfs/rootfs-stage31/data/inc/udhcpc-trigger b/core/rootfs/rootfs-stage31/data/inc/udhcpc-trigger index 7e7e65f2..15fb59bf 100755 --- a/core/rootfs/rootfs-stage31/data/inc/udhcpc-trigger +++ b/core/rootfs/rootfs-stage31/data/inc/udhcpc-trigger @@ -82,6 +82,9 @@ if [ -n "$search" ]; then echo "SLX_NET_SEARCH='$search'" >> /run/config fi +for i in $ntpsrv; do + echo "$i" >> "/run/ntpsrv" +done # Hostname if [ -z "$hostname" ]; then |