mirror of
https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update.git
synced 2025-07-15 08:24:37 +02:00
Refactor routerboard firmware upgrade process for improved clarity and logging; correct variable usage in final report generation
This commit is contained in:
parent
7faf9fb3b7
commit
cf5f02998a
1 changed files with 13 additions and 21 deletions
34
v3.rsc
34
v3.rsc
|
@ -682,34 +682,29 @@
|
|||
## Steps 2 and 3 are fired only if script is set to automatically update device and if new RouterOs is available.
|
||||
:if ($scriptStep = 2) do={
|
||||
:log info "$SMP The script is in the second step, updating Routerboard firmware."
|
||||
## RouterOS is the latest, let's check for upgraded routerboard firmware
|
||||
if ($deviceRbCurrentFw != $deviceRbUpgradeFw) do={
|
||||
:log info "$SMP Upgrading routerboard firmware from v.$deviceRbCurrentFw to v.$deviceRbUpgradeFw"
|
||||
|
||||
/system routerboard upgrade
|
||||
## Wait until the upgrade is completed
|
||||
:delay 2s
|
||||
:log info "$SMP routerboard upgrade process was completed, going to reboot in a moment!";
|
||||
:log info "$SMP Upgrading routerboard firmware from v.$deviceRbCurrentFw to v.$deviceRbUpgradeFw"
|
||||
|
||||
## Set scheduled task to send final report on the next boot, task will be deleted when it is done. (That is why you should keep original script name)
|
||||
/system scheduler add name=BKPUPD-NEXT-BOOT-TASK on-event=":delay 5s; /system scheduler remove BKPUPD-NEXT-BOOT-TASK; :global buGlobalVarUpdateStep 3; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0
|
||||
|
||||
## Reboot system to boot with new firmware
|
||||
/system reboot;
|
||||
} else={
|
||||
:log info "$SMP It appears that your routerboard is already up to date, skipping this step";
|
||||
:set scriptStep 3;
|
||||
};
|
||||
/system routerboard upgrade
|
||||
## Wait until the upgrade is completed
|
||||
:delay 2s
|
||||
:log info "$SMP routerboard upgrade process was completed, going to reboot in a moment!";
|
||||
|
||||
## Set scheduled task to send final report on the next boot, task will be deleted when it is done. (That is why you should keep original script name)
|
||||
/system scheduler add name=BKPUPD-NEXT-BOOT-TASK on-event=":delay 5s; /system scheduler remove BKPUPD-NEXT-BOOT-TASK; :global buGlobalVarScriptStep 3; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0
|
||||
|
||||
## Reboot system to boot with new firmware
|
||||
/system reboot;
|
||||
}
|
||||
|
||||
## STEP THREE: Last step (after second reboot) sending final report
|
||||
## Steps 2 and 3 are fired only if script is set to automatically update device and if new RouterOs is available.
|
||||
## This step is executed after some delay
|
||||
:if ($updateStep = 3) do={
|
||||
:if ($scriptStep = 3) do={
|
||||
:log info ("$SMP The script is in the third step, sending final report.")
|
||||
|
||||
:global buGlobalVarTargetOsVersion
|
||||
:local targetOsVersion $buGlobalVarScriptStep
|
||||
:local targetOsVersion $buGlobalVarTargetOsVersion
|
||||
:do {/system script environment remove buGlobalVarTargetOsVersion} on-error={}
|
||||
|
||||
|
||||
|
@ -727,9 +722,6 @@
|
|||
:set mailStep3Body ($mailStep3Body . "\n\n" . $mailBodyDeviceInfo . "\n\n" . $mailBodyCopyright)
|
||||
|
||||
:set mailAttachments [$FuncCreateBackups $backupNameAfterUpdate $backupPassword $sensitiveDataInConfig];
|
||||
|
||||
# Send email with final report
|
||||
#$FuncSendEmailSafe $emailAddress $mailStep3Subject $mailStep3Body ""
|
||||
} else={
|
||||
:log error "$SMP The script was unable to verify that the new RouterOS version was installed, target version: `$targetOsVersion`, current version: `$runningOsVersion`"
|
||||
:set mailStep3Subject ($mailStep3Subject . " - Update failed")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue