Offer a way to sync time at boot in the first boot version of configure-stormux.

This commit is contained in:
Storm Dragon 2024-05-24 15:51:40 -04:00
parent 88d7d12c69
commit 134d25682b
3 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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."

View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
date_time=$(curl -s http://worldtimeapi.org/api/ip | grep -oP '(?<="datetime":")[^"]*')
date -s "$date_time"