2023-08-07 13:11:14 +02:00
|
|
|
#!rsc by RouterOS
|
|
|
|
# RouterOS script: capsman-rolling-upgrade%TEMPL%
|
2025-01-02 00:04:06 +01:00
|
|
|
# Copyright (c) 2018-2025 Christian Hesse <mail@eworm.de>
|
2023-08-07 13:11:14 +02:00
|
|
|
# Michael Gisbers <michael@gisbers.de>
|
2025-01-24 20:46:11 +01:00
|
|
|
# https://rsc.eworm.de/COPYING.md
|
2023-08-07 13:11:14 +02:00
|
|
|
#
|
2024-07-11 08:45:53 +02:00
|
|
|
# provides: capsman-rolling-upgrade%TEMPL%
|
2025-02-07 17:39:48 +01:00
|
|
|
# requires RouterOS, version=7.15
|
2023-08-07 13:11:14 +02:00
|
|
|
#
|
|
|
|
# upgrade CAPs one after another
|
2025-01-24 20:46:11 +01:00
|
|
|
# https://rsc.eworm.de/doc/capsman-rolling-upgrade.md
|
2023-08-07 13:11:14 +02:00
|
|
|
#
|
2023-11-14 17:31:42 +01:00
|
|
|
# !! This is just a template to generate the real script!
|
|
|
|
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
|
2023-08-07 13:11:14 +02:00
|
|
|
|
2024-12-06 10:31:51 +01:00
|
|
|
:local ExitOK false;
|
2025-05-06 09:44:23 +02:00
|
|
|
:onerror Err {
|
2025-05-06 14:08:36 +02:00
|
|
|
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
|
|
|
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
|
|
|
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
|
2024-03-06 15:28:55 +01:00
|
|
|
:local ScriptName [ :jobname ];
|
2023-08-07 13:11:14 +02:00
|
|
|
|
2024-03-08 12:45:37 +01:00
|
|
|
:global LogPrint;
|
2024-03-04 13:48:00 +01:00
|
|
|
:global ScriptLock;
|
2023-08-07 13:11:14 +02:00
|
|
|
|
2024-03-05 16:12:36 +01:00
|
|
|
:if ([ $ScriptLock $ScriptName ] = false) do={
|
2024-12-06 10:31:51 +01:00
|
|
|
:set ExitOK true;
|
2024-03-06 15:28:55 +01:00
|
|
|
:error false;
|
2024-03-05 16:12:36 +01:00
|
|
|
}
|
2023-08-07 13:11:14 +02:00
|
|
|
|
2024-03-04 13:48:00 +01:00
|
|
|
:local InstalledVersion [ /system/package/update/get installed-version ];
|
|
|
|
|
|
|
|
:local RemoteCapCount [ :len [ /caps-man/remote-cap/find ] ];
|
|
|
|
:local RemoteCapCount [ :len [ /interface/wifi/capsman/remote-cap/find ] ];
|
|
|
|
:if ($RemoteCapCount > 0) do={
|
|
|
|
:local Delay (600 / $RemoteCapCount);
|
|
|
|
:if ($Delay > 120) do={ :set Delay 120; }
|
|
|
|
:foreach RemoteCap in=[ /caps-man/remote-cap/find where version!=$InstalledVersion ] do={
|
|
|
|
:foreach RemoteCap in=[ /interface/wifi/capsman/remote-cap/find where version!=$InstalledVersion ] do={
|
|
|
|
:local RemoteCapVal [ /caps-man/remote-cap/get $RemoteCap ];
|
|
|
|
:local RemoteCapVal [ /interface/wifi/capsman/remote-cap/get $RemoteCap ];
|
|
|
|
:if ([ :len $RemoteCapVal ] > 1) do={
|
2023-11-14 10:10:56 +01:00
|
|
|
# NOT /caps-man/ #
|
2024-03-04 13:48:00 +01:00
|
|
|
:set ($RemoteCapVal->"name") ($RemoteCapVal->"common-name");
|
2023-11-14 10:10:56 +01:00
|
|
|
# NOT /caps-man/ #
|
2024-03-08 12:45:37 +01:00
|
|
|
$LogPrint info $ScriptName ("Starting upgrade for " . $RemoteCapVal->"name" . \
|
|
|
|
" (" . $RemoteCapVal->"identity" . ")...");
|
2024-03-04 13:48:00 +01:00
|
|
|
/caps-man/remote-cap/upgrade $RemoteCap;
|
|
|
|
/interface/wifi/capsman/remote-cap/upgrade $RemoteCap;
|
|
|
|
} else={
|
2024-03-08 12:45:37 +01:00
|
|
|
$LogPrint warning $ScriptName ("Remote CAP vanished, skipping upgrade.");
|
2024-03-04 13:48:00 +01:00
|
|
|
}
|
|
|
|
:delay ($Delay . "s");
|
2023-08-07 13:11:14 +02:00
|
|
|
}
|
|
|
|
}
|
2025-05-06 09:44:23 +02:00
|
|
|
} do={
|
|
|
|
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
|
2024-12-06 10:31:51 +01:00
|
|
|
}
|