Offer a way to sync time at boot in the first boot version of configure-stormux.
This commit is contained in:
parent
88d7d12c69
commit
134d25682b
11
pi4/files/etc/systemd/system/time_sync_at_boot.service
Normal file
11
pi4/files/etc/systemd/system/time_sync_at_boot.service
Normal 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
|
@ -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."
|
||||
|
4
pi4/files/usr/local/bin/sync_time.sh
Executable file
4
pi4/files/usr/local/bin/sync_time.sh
Executable 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"
|
Loading…
Reference in New Issue
Block a user