:log info ("New patch version of RouterOS firmware is available.");
} else={
:log info ("New major version of RouterOS firmware is available. You have to update it manually.");
:set isUpdateAvailable false;
#Send email just once
:if ($beePatchUpdateInapplicable != true and $emailEnabled = true) do={
:log info ("Email was sent just once.");
/tool e-mail send to="$emailAddress" subject="Router: $[/system identity get name], new major version of RouterOS firmware is available: v$osVerNew" body="New major version of RouterOS firmware is available. You have to update it manually.. \r\n\r\nRouter name: $[/system identity get name]\r\nCurrent RouterOS version: $osVerCurrent; Routerboard firmware: $[/system routerboard get current-firmware]; Update channel: $[/system package update get channel]; \r\nBoard name: $[/system resource get board-name]; Serial number: $[/system routerboard get serial-number]; \r\n\r\n Changelog: https://mikrotik.com/download/changelogs/current-release-tree";
:delay 5s;
# If notification was sent, we no longer bother with it.
:if ([/tool e-mail get last-status] = "succeeded") do={
:global beePatchUpdateInapplicable true;
}
}
}
}
#Keep environment clean
:if ($isUpdateAvailable = true and $beePatchUpdateInapplicable = true) do={
/tool e-mail send to=$emailAddress subject="Upgrade router: $[/system identity get name] FW has been started" body="Upgrading RouterOS on router $[/system identity get name] from $osVerCurrent to $osVerNew \r\nYou will recieve final report with detailed information when upgrade process is finished. If you have not got second email in next 5 minutes, then probably something went wrong." file=$attachments;
## Set scheduled task to upgrade routerboard firmware on the next boot, task will be deleted when upgrade is done. (That is why you should keep original script name)
## command is reincarnation of the "upgrade" command - doing exactly the same but under a different name
/system package update install;
}
}
## Second step (after first reboot) routerboard firmware upgrade
:if ( $updateStep = "routerboardUpgrade") do={
## RouterOS latest, let's check for updated firmware
:if ( [/system routerboard get current-firmware] != [/system routerboard get upgrade-firmware]) do={
## New version of firmware available, let's upgrade
:log info ("Upgrading firmware on router $[/system identity get name], board name: $[/system resource get board-name], serial number: $[/system routerboard get serial-number] | From $[/system routerboard get current-firmware] to $[/system routerboard get upgrade-firmware]");
## Last step (after second reboot) sending final report
:if ( $updateStep = "finalReport") do={
:log info "Upgrading RouterOS and routerboard firmware finished. Current RouterOS version: $[/system package update get installed-version], routerboard firmware: $[/system routerboard get current-firmware].";
:if ($emailEnabled = true) do={
/tool e-mail send to="$emailAddress" subject="Router: $[/system identity get name] has been upgraded with new FW!" body="Upgrading RouterOS and routerboard firmware finished. \r\n\r\nRouter name: $[/system identity get name]\r\nCurrent RouterOS version: $[/system package update get installed-version]; Routerboard firmware: $[/system routerboard get current-firmware]; Update channel: $[/system package update get channel]; \r\nBoard name: $[/system resource get board-name]; Serial number: $[/system routerboard get serial-number]; \r\n\r\n Changelog: https://mikrotik.com/download/changelogs/current-release-tree";
}
}
:log info ("Firmware updater has finished it's job");