Refactor routerboard firmware upgrade process for improved clarity and logging; correct variable usage in final report generation

This commit is contained in:
Alexander Tebiev 2025-04-11 15:09:34 +02:00
parent 7faf9fb3b7
commit cf5f02998a

16
v3.rsc
View file

@ -682,8 +682,7 @@
## 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
@ -692,24 +691,20 @@
: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 buGlobalVarUpdateStep 3; :delay 10s; /system script run BackupAndUpdate;" start-time=startup interval=0
/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;
} else={
:log info "$SMP It appears that your routerboard is already up to date, skipping this step";
:set scriptStep 3;
};
}
## 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")