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