From 134d25682bac681f46f24545bb5132724589361b Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 24 May 2024 15:51:40 -0400 Subject: [PATCH] Offer a way to sync time at boot in the first boot version of configure-stormux. --- .../etc/systemd/system/time_sync_at_boot.service | 11 +++++++++++ pi4/files/usr/local/bin/configure-stormux | 11 +++++++++++ pi4/files/usr/local/bin/sync_time.sh | 4 ++++ 3 files changed, 26 insertions(+) create mode 100644 pi4/files/etc/systemd/system/time_sync_at_boot.service create mode 100755 pi4/files/usr/local/bin/sync_time.sh diff --git a/pi4/files/etc/systemd/system/time_sync_at_boot.service b/pi4/files/etc/systemd/system/time_sync_at_boot.service new file mode 100644 index 0000000..c49ba4c --- /dev/null +++ b/pi4/files/etc/systemd/system/time_sync_at_boot.service @@ -0,0 +1,11 @@ +[Unit] +Description=Update system time from worldtimeapi.org +After=network-online.target +Wants=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/sync_time.sh + +[Install] +WantedBy=multi-user.target diff --git a/pi4/files/usr/local/bin/configure-stormux b/pi4/files/usr/local/bin/configure-stormux index 298af68..7ff7fa7 100755 --- a/pi4/files/usr/local/bin/configure-stormux +++ b/pi4/files/usr/local/bin/configure-stormux @@ -101,6 +101,17 @@ if ping -qc1 -W 1 stormux.org &> /dev/null; then echo "Current date and time: $date_time" # set date and time date -s "$date_time" + echo "If your Pi does not have a CMOS battery and is powered off regularly, it may take a while for the time to be set correctly after boot." + echo "Stormux provides a service to sync the time after internet connection is established." + read -rp "Would you like the time to sync as soon as the Pi connects to the internet? " answer + answer="${answer:0:1}" + if [[ "${answer,,}" == "y" ]]; then + systemctl enable time_sync_at_boot.service + else + echo "Time sync at boot skipped." + echo "If you change your mind later, simply type:" + echo "sudo systemctl enable time_sync_at_boot.service" + fi set_timezone else echo "Please connect to the internet and run ${0##*/} again." diff --git a/pi4/files/usr/local/bin/sync_time.sh b/pi4/files/usr/local/bin/sync_time.sh new file mode 100755 index 0000000..aea1925 --- /dev/null +++ b/pi4/files/usr/local/bin/sync_time.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +date_time=$(curl -s http://worldtimeapi.org/api/ip | grep -oP '(?<="datetime":")[^"]*') +date -s "$date_time"