diff options
author | Christian Hesse <mail@eworm.de> | 2023-01-19 22:43:03 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2023-01-20 11:26:53 +0100 |
commit | de9dde1b1418e6d5a93f16a027b6208ca89394bf (patch) | |
tree | 1a42dd895c6a4590cc8eaea5eefd46651b08b4f6 /global-functions | |
parent | 9887ab084996cd8babd60c534edd5f7ff87e49f3 (diff) |
global-functions: $ScriptInstallUpdate: add a version check for scripts
New RouterOS releases bring new features, and thus new syntax.
Installing a new script on old RouterOS results in syntax errors. We
want to give clear warning messages, so by adding an extra comment into
the script...
# requires RouterOS, version=7.8beta3
... installing on unsupported RouterOS version is mitigated.
Diffstat (limited to 'global-functions')
-rw-r--r-- | global-functions | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/global-functions b/global-functions index ac5770b..78af95d 100644 --- a/global-functions +++ b/global-functions @@ -700,9 +700,12 @@ :global ScriptUpdatesUrlSuffix; :global CertificateAvailable; + :global EitherOr; + :global Grep; :global IfThenElse; :global LogPrintExit2; :global ParseKeyValueStore; + :global RequiredRouterOS; :global SendNotification2; :global SymbolForNotification; :global ValidateSyntax; @@ -773,18 +776,24 @@ :if ([ :len $SourceNew ] > 0) do={ :if ($SourceNew != $ScriptVal->"source") do={ :if ([ :pick $SourceNew 0 18 ] = "#!rsc by RouterOS\n") do={ - :if ([ $ValidateSyntax $SourceNew ] = true) do={ - $LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false; - /system/script/set owner=($ScriptVal->"name") source=$SourceNew $Script; - :if ($ScriptVal->"name" = "global-config") do={ - :set ReloadGlobalConfig true; - } - :if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={ - :set ReloadGlobalFunctions true; + :local Required ([ $ParseKeyValueStore [ $Grep $SourceNew "# requires RouterOS, " ] ]->"version"); + :if ([ $RequiredRouterOS $0 [ $EitherOr $Required "0.0" ] false ] = true) do={ + :if ([ $ValidateSyntax $SourceNew ] = true) do={ + $LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false; + /system/script/set owner=($ScriptVal->"name") source=$SourceNew $Script; + :if ($ScriptVal->"name" = "global-config") do={ + :set ReloadGlobalConfig true; + } + :if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={ + :set ReloadGlobalFunctions true; + } + } else={ + $LogPrintExit2 warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \ + "' failed! Ignoring!") false; } } else={ - $LogPrintExit2 warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \ - "' failed! Ignoring!") false; + $LogPrintExit2 warning $0 ("The script '" . $ScriptVal->"name" . "' requires RouterOS " . \ + $Required . ", which is not met by your installation. Ignoring!") false; } } else={ $LogPrintExit2 warning $0 ("Looks like new script '" . $ScriptVal->"name" . \ |