Use NTP client to find internet; limit backup by time of the day; improve docs

This commit is contained in:
Pothi Kalimuthu 2025-06-03 05:49:53 +05:30
parent 3a233e0a3f
commit 20a1812d1f
No known key found for this signature in database
GPG key ID: 57069303D36E3093

View file

@ -1,44 +1,52 @@
# Initialize the router with default values, run backup scripts and check for updates!
# Version: 2
# Note: The policy of the script should match the policy of the scheduler that calls this script.
# changelog
# Version: 4
# change log
# version: 4
# - date: 2025-05-31
#. - do not execute backup scripts after 12 noon.
# version: 3
# - date: 2023-08-20
# - use NTP client to test for internet.
# - No more timeout for stable internet. Wait indefinitely until stable internet.
# version: 2
# - date: 2022-11-18
# - introduction of timeout to check internet
:global adminEmail "noreply@example.com"
:global adminPh 9894998949
:global genericLogFileName "genericLog"
:global cloudPass ""
:global minSpeed 0
:global waitForDNS do={
:local pingIP 1
:local isUP 0
:local timeout 5
:while ( $pingIP = 1 ) do={
:do { :set $pingIP [:resolve g.co] } on-error={
:delay 60s
:set isUP ($isUP+1)
:if ($isUP = $timeout) do={ :error "Internet timed out after $timeout minutes!" }
}
}
:while ( ([/system/ntp/client print as-value])->"status" != "synchronized" ) do={
:delay 60s;
# :log info "No internet, yet."
}
$waitForDNS
:log info "Init script execution has started."
:log info "Connected to internet. Time synced."
# /system ntp client set enabled=yes; :delay 3s
:log info "Init script has started..."
/system script
:local commonScripts {"backup-cron"; "backup-scripts"; "cloud-backup"; "firmware-check-rb"; "firmware-check-ros";}
:local commonScripts {"firmware-check-rb"; "firmware-check-ros";}
:local initScripts ($commonScripts, "firmware-check-lte")
/system script
:foreach scriptName in $initScripts do={
:do { run $scriptName } on-error={ :log error "Error running the script $scriptName\n" }
:delay 30s
}
:log info "Init script finished execution!"
:local currentHour [:tonum [:pick [/system clock get time] 0 2]]
:local backupScripts {"backup-cron"; "backup-scripts"}
:if ($currentHour < 7) do={
:foreach scriptName in $backupScripts do={
:do { run $scriptName } on-error={:log error "Error running $scriptName"}
:delay 30s
}
} else={
:log info "Automated backups aren't taken after 7am."
}
:log info "Init script execution is completed."