2022-11-11 13:06:52 +05:30
|
|
|
# Initialize the router with default values, run backup scripts and check for updates!
|
|
|
|
|
2022-11-18 10:07:05 +05:30
|
|
|
# Version: 2
|
|
|
|
|
|
|
|
# changelog
|
|
|
|
# version: 2
|
|
|
|
# - date: 2022-11-18
|
|
|
|
# - introduction of timeout to check internet
|
|
|
|
|
2022-11-11 13:06:52 +05:30
|
|
|
:global adminEmail "noreply@example.com"
|
|
|
|
:global cloudPass ""
|
|
|
|
|
2022-11-18 10:07:05 +05:30
|
|
|
:local isUP 0
|
|
|
|
:local timeout 5
|
|
|
|
|
2022-11-11 13:06:52 +05:30
|
|
|
/interface/detect-internet
|
|
|
|
set detect-interface-list=WAN
|
|
|
|
state
|
2022-11-18 10:07:05 +05:30
|
|
|
|
2022-11-11 13:06:52 +05:30
|
|
|
:do {
|
|
|
|
:delay 60s
|
|
|
|
:set $internetStatus ([:pick [print as-value] 0]->"state")
|
|
|
|
# :log info "Waiting for internet..."
|
2022-11-18 10:07:05 +05:30
|
|
|
|
|
|
|
:set isUP ($isUP+1)
|
|
|
|
:if ($isUP = $timeout) do={ :error "Internet timed out after $timeout minutes!" }
|
|
|
|
|
2022-11-11 13:06:52 +05:30
|
|
|
} while ($internetStatus != "internet")
|
2022-11-18 10:07:05 +05:30
|
|
|
|
2022-11-11 13:06:52 +05:30
|
|
|
# :log info "Connected to internet."
|
|
|
|
|
|
|
|
:log info "Init script started."
|
|
|
|
|
|
|
|
/system script
|
|
|
|
|
2025-06-02 06:47:02 +05:30
|
|
|
:local commonScripts {"cloud-backup"; "firmware-check"}
|
2024-02-16 10:10:22 +05:30
|
|
|
:local initScripts ("wifi-enable", $commonScripts)
|
2022-11-11 13:06:52 +05:30
|
|
|
|
|
|
|
:foreach scriptName in $initScripts do={
|
|
|
|
:do { run $scriptName } on-error={:log error "Error running $scriptName"}
|
|
|
|
:delay 30s
|
|
|
|
}
|
|
|
|
|
2025-06-02 06:47:02 +05:30
|
|
|
:local currentHour [:tonum [:pick [/system clock get time] 0 2]]
|
|
|
|
|
|
|
|
:if ($currentHour < 12) do={
|
|
|
|
:local backupScripts {"backup-cron"; "backup-scripts"}
|
|
|
|
: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 12 noon."
|
|
|
|
}
|
|
|
|
|
2022-11-11 13:06:52 +05:30
|
|
|
:log info "Init script ended."
|