2023-03-07 09:57:42 +00:00
|
|
|
#!rsc by RouterOS
|
|
|
|
# RouterOS script: firmware-upgrade-reboot
|
2024-01-01 14:25:25 +00:00
|
|
|
# Copyright (c) 2022-2024 Christian Hesse <mail@eworm.de>
|
2023-03-07 09:57:42 +00:00
|
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
|
|
|
#
|
2023-11-15 20:31:18 +00:00
|
|
|
# requires RouterOS, version=7.12
|
|
|
|
#
|
2023-03-07 09:57:42 +00:00
|
|
|
# install firmware upgrade, and reboot
|
|
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/firmware-upgrade-reboot.md
|
|
|
|
|
|
|
|
:global GlobalFunctionsReady;
|
|
|
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
|
|
|
|
2024-03-06 14:28:55 +00:00
|
|
|
:do {
|
|
|
|
:local ScriptName [ :jobname ];
|
2024-03-04 12:48:01 +00:00
|
|
|
|
2024-03-08 11:45:38 +00:00
|
|
|
:global LogPrint;
|
2024-03-04 12:48:01 +00:00
|
|
|
:global ScriptLock;
|
|
|
|
:global VersionToNum;
|
|
|
|
|
2024-03-05 15:12:36 +00:00
|
|
|
:if ([ $ScriptLock $ScriptName ] = false) do={
|
2024-03-06 14:28:55 +00:00
|
|
|
:error false;
|
2024-03-05 15:12:36 +00:00
|
|
|
}
|
2024-03-04 12:48:01 +00:00
|
|
|
|
|
|
|
:local RouterBoard [ /system/routerboard/get ];
|
|
|
|
:if ($RouterBoard->"current-firmware" = $RouterBoard->"upgrade-firmware") do={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint info $ScriptName ("Current and upgrade firmware match with version " . \
|
|
|
|
$RouterBoard->"current-firmware" . ".");
|
2024-03-06 14:28:55 +00:00
|
|
|
:error true;
|
2024-03-04 12:48:01 +00:00
|
|
|
}
|
|
|
|
:if ([ $VersionToNum ($RouterBoard->"current-firmware") ] > [ $VersionToNum ($RouterBoard->"upgrade-firmware") ]) do={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint info $ScriptName ("Different firmware version is available, but it is a downgrade. Ignoring.");
|
2024-03-06 14:28:55 +00:00
|
|
|
:error true;
|
2024-03-04 12:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
:if ([ /system/routerboard/settings/get auto-upgrade ] = false) do={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint info $ScriptName ("Firmware version " . $RouterBoard->"upgrade-firmware" . \
|
|
|
|
" is available, upgrading.");
|
2024-03-04 12:48:01 +00:00
|
|
|
/system/routerboard/upgrade;
|
|
|
|
}
|
|
|
|
|
|
|
|
:while ([ :len [ /log/find where topics=({"system";"info";"critical"}) \
|
|
|
|
message="Firmware upgraded successfully, please reboot for changes to take effect!" ] ] = 0) do={
|
|
|
|
:delay 1s;
|
|
|
|
}
|
|
|
|
|
|
|
|
:local Uptime [ /system/resource/get uptime ];
|
|
|
|
:if ($Uptime < 1m) do={
|
|
|
|
:delay $Uptime;
|
|
|
|
}
|
|
|
|
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint info $ScriptName ("Firmware upgrade successful, rebooting.");
|
2024-03-04 12:48:01 +00:00
|
|
|
/system/reboot;
|
2024-03-06 14:28:55 +00:00
|
|
|
} on-error={ }
|