global-functions: $ScriptInstallUpdate: support checking for device-mode features

This commit is contained in:
Christian Hesse 2025-01-29 09:45:25 +01:00
parent 106a9bddef
commit b177e298d7

View file

@ -5,6 +5,7 @@
# https://rsc.eworm.de/COPYING.md # https://rsc.eworm.de/COPYING.md
# #
# requires RouterOS, version=7.14 # requires RouterOS, version=7.14
# requires device-mode, fetch, scheduler
# #
# global functions # global functions
# https://rsc.eworm.de/ # https://rsc.eworm.de/
@ -1071,6 +1072,7 @@
:local ExpectedConfigVersionBefore $ExpectedConfigVersion; :local ExpectedConfigVersionBefore $ExpectedConfigVersion;
:local ReloadGlobalFunctions false; :local ReloadGlobalFunctions false;
:local ReloadGlobalConfig false; :local ReloadGlobalConfig false;
:local DeviceMode [ /system/device-mode/get ];
:foreach Script in=[ /system/script/find where source~"^#!rsc by RouterOS\r?\n" ] do={ :foreach Script in=[ /system/script/find where source~"^#!rsc by RouterOS\r?\n" ] do={
:local ScriptVal [ /system/script/get $Script ]; :local ScriptVal [ /system/script/get $Script ];
@ -1113,19 +1115,31 @@
:if ([ :pick $SourceNew 0 18 ] = "#!rsc by RouterOS\n") do={ :if ([ :pick $SourceNew 0 18 ] = "#!rsc by RouterOS\n") do={
:local Required ([ $ParseKeyValueStore [ $Grep $SourceNew ("\23 requires RouterOS, ") ] ]->"version"); :local Required ([ $ParseKeyValueStore [ $Grep $SourceNew ("\23 requires RouterOS, ") ] ]->"version");
:if ([ $RequiredRouterOS $0 [ $EitherOr $Required "0.0" ] false ] = true) do={ :if ([ $RequiredRouterOS $0 [ $EitherOr $Required "0.0" ] false ] = true) do={
:if ([ $ValidateSyntax $SourceNew ] = true) do={ :local RequiredDM [ $ParseKeyValueStore [ $Grep $SourceNew ("\23 requires device-mode, ") ] ];
$LogPrint info $0 ("Updating script: " . $ScriptVal->"name"); :local MissingDM ({});
/system/script/set owner=($ScriptVal->"name") \ :foreach Feature,Value in=$RequiredDM do={
source=[ $IfThenElse ($ScriptUpdatesCRLF = true) $SourceCRLF $SourceNew ] $Script; :if ([ :typeof ($DeviceMode->$Feature) ] = "bool" && ($DeviceMode->$Feature) = false) do={
:if ($ScriptVal->"name" = "global-config") do={ :set MissingDM ($MissingDM, $Feature);
:set ReloadGlobalConfig true;
} }
:if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={ }
:set ReloadGlobalFunctions true; :if ([ :len $MissingDM ] = 0) do={
:if ([ $ValidateSyntax $SourceNew ] = true) do={
$LogPrint info $0 ("Updating script: " . $ScriptVal->"name");
/system/script/set owner=($ScriptVal->"name") \
source=[ $IfThenElse ($ScriptUpdatesCRLF = true) $SourceCRLF $SourceNew ] $Script;
:if ($ScriptVal->"name" = "global-config") do={
:set ReloadGlobalConfig true;
}
:if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={
:set ReloadGlobalFunctions true;
}
} else={
$LogPrint warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \
"' failed! Ignoring!");
} }
} else={ } else={
$LogPrint warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \ $LogPrintOnce warning $0 ("The script '" . $ScriptVal->"name" . "' requires disabled " . \
"' failed! Ignoring!"); "device-mode features (" . [ :tostr $MissingDM ] . "). Ignoring!");
} }
} else={ } else={
$LogPrintOnce warning $0 ("The script '" . $ScriptVal->"name" . "' requires RouterOS " . \ $LogPrintOnce warning $0 ("The script '" . $ScriptVal->"name" . "' requires RouterOS " . \