global-functions: switch to $LogPrint

This commit is contained in:
Christian Hesse 2024-03-08 12:45:38 +01:00
parent 6715696ba1
commit 9dd1b768ee

View file

@ -102,18 +102,18 @@
:local CommonName [ :tostr $1 ]; :local CommonName [ :tostr $1 ];
:global CertificateDownload; :global CertificateDownload;
:global LogPrintExit2; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:if ([ /system/resource/get free-hdd-space ] < 8388608 && \ :if ([ /system/resource/get free-hdd-space ] < 8388608 && \
[ /certificate/settings/get crl-download ] = true && \ [ /certificate/settings/get crl-download ] = true && \
[ /certificate/settings/get crl-store ] = "system") do={ [ /certificate/settings/get crl-store ] = "system") do={
$LogPrintExit2 warning $0 ("This system has low free flash space but " . \ $LogPrint warning $0 ("This system has low free flash space but " . \
"is configured to download certificate CRLs to system!") false; "is configured to download certificate CRLs to system!");
} }
:if ([ :len [ /certificate/find where common-name=$CommonName ] ] = 0) do={ :if ([ :len [ /certificate/find where common-name=$CommonName ] ] = 0) do={
$LogPrintExit2 info $0 ("Certificate with CommonName \"" . $CommonName . "\" not available.") false; $LogPrint info $0 ("Certificate with CommonName \"" . $CommonName . "\" not available.");
:if ([ $CertificateDownload $CommonName ] = false) do={ :if ([ $CertificateDownload $CommonName ] = false) do={
:return false; :return false;
} }
@ -122,8 +122,8 @@
:local CertVal [ /certificate/get [ find where common-name=$CommonName ] ]; :local CertVal [ /certificate/get [ find where common-name=$CommonName ] ];
:while (($CertVal->"akid") != "" && ($CertVal->"akid") != ($CertVal->"skid")) do={ :while (($CertVal->"akid") != "" && ($CertVal->"akid") != ($CertVal->"skid")) do={
:if ([ :len [ /certificate/find where skid=($CertVal->"akid") ] ] = 0) do={ :if ([ :len [ /certificate/find where skid=($CertVal->"akid") ] ] = 0) do={
$LogPrintExit2 info $0 ("Certificate chain for \"" . $CommonName . \ $LogPrint info $0 ("Certificate chain for \"" . $CommonName . \
"\" is incomplete, missing \"" . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\".") false; "\" is incomplete, missing \"" . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\".");
:if ([ $CertificateDownload $CommonName ] = false) do={ :if ([ $CertificateDownload $CommonName ] = false) do={
:return false; :return false;
} }
@ -142,12 +142,12 @@
:global ScriptUpdatesUrlSuffix; :global ScriptUpdatesUrlSuffix;
:global CertificateNameByCN; :global CertificateNameByCN;
:global LogPrintExit2; :global LogPrint;
:global UrlEncode; :global UrlEncode;
:global WaitForFile; :global WaitForFile;
$LogPrintExit2 info $0 ("Downloading and importing certificate with " . \ $LogPrint info $0 ("Downloading and importing certificate with " . \
"CommonName \"" . $CommonName . "\".") false; "CommonName \"" . $CommonName . "\".");
:do { :do {
:local LocalFileName ($CommonName . ".pem"); :local LocalFileName ($CommonName . ".pem");
:local UrlFileName ([ $UrlEncode $CommonName ] . ".pem"); :local UrlFileName ([ $UrlEncode $CommonName ] . ".pem");
@ -163,8 +163,7 @@
$CertificateNameByCN [ /certificate/get $Cert common-name ]; $CertificateNameByCN [ /certificate/get $Cert common-name ];
} }
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed importing certificate with " . \ $LogPrint warning $0 ("Failed importing certificate with CommonName \"" . $CommonName . "\"!");
"CommonName \"" . $CommonName . "\"!") false;
:return false; :return false;
} }
:return true; :return true;
@ -309,7 +308,7 @@
:global CertificateAvailable; :global CertificateAvailable;
:global CleanFilePath; :global CleanFilePath;
:global LogPrintExit2; :global LogPrint;
:global MkDir; :global MkDir;
:global WaitForFile; :global WaitForFile;
@ -324,23 +323,23 @@
:local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ]; :local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ];
:if ([ $MkDir $PkgDir ] = false) do={ :if ([ $MkDir $PkgDir ] = false) do={
$LogPrintExit2 warning $0 ("Failed creating directory, not downloading package.") false; $LogPrint warning $0 ("Failed creating directory, not downloading package.");
:return false; :return false;
} }
:if ([ :len [ /file/find where name=$PkgDest type="package" ] ] > 0) do={ :if ([ :len [ /file/find where name=$PkgDest type="package" ] ] > 0) do={
$LogPrintExit2 info $0 ("Package file " . $PkgName . " already exists.") false; $LogPrint info $0 ("Package file " . $PkgName . " already exists.");
:return true; :return true;
} }
:if ([ $CertificateAvailable "R3" ] = false) do={ :if ([ $CertificateAvailable "R3" ] = false) do={
$LogPrintExit2 error $0 ("Downloading required certificate failed.") false; $LogPrint error $0 ("Downloading required certificate failed.");
:return false; :return false;
} }
:local Url ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile); :local Url ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile);
$LogPrintExit2 info $0 ("Downloading package file '" . $PkgName . "'...") false; $LogPrint info $0 ("Downloading package file '" . $PkgName . "'...");
$LogPrintExit2 debug $0 ("... from url: " . $Url) false; $LogPrint debug $0 ("... from url: " . $Url);
:local Retry 3; :local Retry 3;
:while ($Retry > 0) do={ :while ($Retry > 0) do={
:do { :do {
@ -351,14 +350,14 @@
:return true; :return true;
} }
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Downloading package file failed.") false; $LogPrint debug $0 ("Downloading package file failed.");
} }
/file/remove [ find where name=$PkgDest ]; /file/remove [ find where name=$PkgDest ];
:set Retry ($Retry - 1); :set Retry ($Retry - 1);
} }
$LogPrintExit2 warning $0 ("Downloading package file '" . $PkgName . "' failed.") false; $LogPrint warning $0 ("Downloading package file '" . $PkgName . "' failed.");
:return false; :return false;
} }
@ -444,7 +443,7 @@
:global CertificateAvailable; :global CertificateAvailable;
:global IsMacLocallyAdministered; :global IsMacLocallyAdministered;
:global LogPrintExit2; :global LogPrint;
:if ([ $IsMacLocallyAdministered $Mac ] = true) do={ :if ([ $IsMacLocallyAdministered $Mac ] = true) do={
:return "locally administered"; :return "locally administered";
@ -452,7 +451,8 @@
:do { :do {
:if ([ $CertificateAvailable "GTS CA 1P5" ] = false) do={ :if ([ $CertificateAvailable "GTS CA 1P5" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; $LogPrint warning $0 ("Downloading required certificate failed.");
:error false;
} }
:local Vendor ([ /tool/fetch check-certificate=yes-without-crl \ :local Vendor ([ /tool/fetch check-certificate=yes-without-crl \
("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data"); ("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data");
@ -461,9 +461,9 @@
:do { :do {
/tool/fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \ /tool/fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \
output=none as-value; output=none as-value;
$LogPrintExit2 debug $0 ("The mac vendor is not known in database.") false; $LogPrint debug $0 ("The mac vendor is not known in database.");
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed getting mac vendor.") false; $LogPrint warning $0 ("Failed getting mac vendor.");
} }
:return "unknown vendor"; :return "unknown vendor";
} }
@ -610,7 +610,7 @@
:global IsTimeSyncCached; :global IsTimeSyncCached;
:global IsTimeSyncResetNtp; :global IsTimeSyncResetNtp;
:global LogPrintExit2; :global LogPrint;
:if ($IsTimeSyncCached = true) do={ :if ($IsTimeSyncCached = true) do={
:return true; :return true;
@ -639,7 +639,7 @@
:if ([ /system/license/get ]->"level" = "free" || \ :if ([ /system/license/get ]->"level" = "free" || \
[ /system/resource/get ]->"board-name" = "x86") do={ [ /system/resource/get ]->"board-name" = "x86") do={
$LogPrintExit2 debug $0 ("No ntp client configured, relying on RTC for CHR free license and x86.") false; $LogPrint debug $0 ("No ntp client configured, relying on RTC for CHR free license and x86.");
:return true; :return true;
} }
@ -651,7 +651,7 @@
:return false; :return false;
} }
$LogPrintExit2 debug $0 ("No time source configured! Returning gracefully...") false; $LogPrint debug $0 ("No time source configured! Returning gracefully...");
:return true; :return true;
} }
@ -717,7 +717,7 @@
:local Name [ :tostr $2 ]; :local Name [ :tostr $2 ];
:local Message [ :tostr $3 ]; :local Message [ :tostr $3 ];
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnceMessages; :global LogPrintOnceMessages;
@ -730,7 +730,7 @@
} }
:set ($LogPrintOnceMessages->$Message) 1; :set ($LogPrintOnceMessages->$Message) 1;
$LogPrintExit2 $Severity $Name $Message false; $LogPrint $Severity $Name $Message;
} }
# get max value # get max value
@ -750,24 +750,24 @@
:local Path [ :tostr $1 ]; :local Path [ :tostr $1 ];
:global CleanFilePath; :global CleanFilePath;
:global LogPrintExit2; :global LogPrint;
:global WaitForFile; :global WaitForFile;
:local MkTmpfs do={ :local MkTmpfs do={
:global LogPrintExit2; :global LogPrint;
:global WaitForFile; :global WaitForFile;
:if ([ :len [ /disk/find where slot=tmpfs type=tmpfs ] ] = 1) do={ :if ([ :len [ /disk/find where slot=tmpfs type=tmpfs ] ] = 1) do={
:return true; :return true;
} }
$LogPrintExit2 info $0 ("Creating disk of type tmpfs.") false; $LogPrint info $0 ("Creating disk of type tmpfs.");
/file/remove [ find where name="tmpfs" type="directory" ]; /file/remove [ find where name="tmpfs" type="directory" ];
:do { :do {
/disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3); /disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3);
$WaitForFile "tmpfs"; $WaitForFile "tmpfs";
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Creating disk of type tmpfs failed!") false; $LogPrint warning $0 ("Creating disk of type tmpfs failed!");
:return false; :return false;
} }
:return true; :return true;
@ -795,7 +795,7 @@
$WaitForFile $File; $WaitForFile $File;
/file/remove $File; /file/remove $File;
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Making directory '" . $Path . "' failed!") false; $LogPrint warning $0 ("Making directory '" . $Path . "' failed!");
:return false; :return false;
} }
@ -926,18 +926,18 @@
:local Warn [ :tostr $3 ]; :local Warn [ :tostr $3 ];
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global VersionToNum; :global VersionToNum;
:if (!($Required ~ "^\\d+\\.\\d+((alpha|beta|rc|\\.)\\d+|)\$")) do={ :if (!($Required ~ "^\\d+\\.\\d+((alpha|beta|rc|\\.)\\d+|)\$")) do={
$LogPrintExit2 error $0 ("No valid RouterOS version: " . $Required) false; $LogPrint error $0 ("No valid RouterOS version: " . $Required);
:return false; :return false;
} }
:if ([ $VersionToNum $Required ] > [ $VersionToNum [ /system/package/update/get installed-version ] ]) do={ :if ([ $VersionToNum $Required ] > [ $VersionToNum [ /system/package/update/get installed-version ] ]) do={
:if ($Warn = "true") do={ :if ($Warn = "true") do={
$LogPrintExit2 warning $0 ("This " . [ $IfThenElse ([ :pick $Caller 0 ] = ("\$")) "function" "script" ] . \ $LogPrint warning $0 ("This " . [ $IfThenElse ([ :pick $Caller 0 ] = ("\$")) "function" "script" ] . \
" '" . $Caller . "' (at least specific functionality) requires RouterOS " . $Required . ". Please update!") false; " '" . $Caller . "' (at least specific functionality) requires RouterOS " . $Required . ". Please update!");
} }
:return false; :return false;
} }
@ -948,7 +948,7 @@
:set ScriptFromTerminal do={ :set ScriptFromTerminal do={
:local Script [ :tostr $1 ]; :local Script [ :tostr $1 ];
:global LogPrintExit2; :global LogPrint;
:foreach Job in=[ /system/script/job/find where script=$Script ] do={ :foreach Job in=[ /system/script/job/find where script=$Script ] do={
:set Job [ /system/script/job/get $Job ]; :set Job [ /system/script/job/get $Job ];
@ -956,11 +956,11 @@
:set Job [ /system/script/job/get [ find where .id=($Job->"parent") ] ]; :set Job [ /system/script/job/get [ find where .id=($Job->"parent") ] ];
} }
:if (($Job->"type") = "login") do={ :if (($Job->"type") = "login") do={
$LogPrintExit2 debug $0 ("Script " . $Script . " started from terminal.") false; $LogPrint debug $0 ("Script " . $Script . " started from terminal.");
:return true; :return true;
} }
} }
$LogPrintExit2 debug $0 ("Script " . $Script . " NOT started from terminal.") false; $LogPrint debug $0 ("Script " . $Script . " NOT started from terminal.");
:return false; :return false;
} }
@ -982,7 +982,7 @@
:global EitherOr; :global EitherOr;
:global Grep; :global Grep;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnce; :global LogPrintOnce;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global RequiredRouterOS; :global RequiredRouterOS;
@ -991,12 +991,12 @@
:global ValidateSyntax; :global ValidateSyntax;
:if ([ $CertificateAvailable "E1" ] = false) do={ :if ([ $CertificateAvailable "E1" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading certificate failed, trying without.") false; $LogPrint warning $0 ("Downloading certificate failed, trying without.");
} }
:foreach Script in=$Scripts do={ :foreach Script in=$Scripts do={
:if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={ :if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
$LogPrintExit2 info $0 ("Adding new script: " . $Script) false; $LogPrint info $0 ("Adding new script: " . $Script);
/system/script/add name=$Script owner=$Script source="#!rsc by RouterOS\n" comment=$NewComment; /system/script/add name=$Script owner=$Script source="#!rsc by RouterOS\n" comment=$NewComment;
} }
} }
@ -1013,8 +1013,8 @@
:foreach Scheduler in=[ /system/scheduler/find where on-event~("\\b" . $ScriptVal->"name" . "\\b") ] do={ :foreach Scheduler in=[ /system/scheduler/find where on-event~("\\b" . $ScriptVal->"name" . "\\b") ] do={
:local SchedulerVal [ /system/scheduler/get $Scheduler ]; :local SchedulerVal [ /system/scheduler/get $Scheduler ];
:if ($ScriptVal->"policy" != $SchedulerVal->"policy") do={ :if ($ScriptVal->"policy" != $SchedulerVal->"policy") do={
$LogPrintExit2 warning $0 ("Policies differ for script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Policies differ for script '" . $ScriptVal->"name" . \
"' and its scheduler '" . $SchedulerVal->"name" . "'!") false; "' and its scheduler '" . $SchedulerVal->"name" . "'!");
} }
} }
@ -1023,7 +1023,7 @@
:local BaseUrl [ $EitherOr ($ScriptInfo->"base-url") $ScriptUpdatesBaseUrl ]; :local BaseUrl [ $EitherOr ($ScriptInfo->"base-url") $ScriptUpdatesBaseUrl ];
:local UrlSuffix [ $EitherOr ($ScriptInfo->"url-suffix") $ScriptUpdatesUrlSuffix ]; :local UrlSuffix [ $EitherOr ($ScriptInfo->"url-suffix") $ScriptUpdatesUrlSuffix ];
:local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix); :local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix);
$LogPrintExit2 debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url) false; $LogPrint debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url);
:local Result [ /tool/fetch check-certificate=yes-without-crl \ :local Result [ /tool/fetch check-certificate=yes-without-crl \
http-header-field=({ $FetchUserAgent }) $Url output=user as-value ]; http-header-field=({ $FetchUserAgent }) $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
@ -1031,11 +1031,11 @@
} }
} on-error={ } on-error={
:if ($ScriptVal->"source" = "#!rsc by RouterOS\n") do={ :if ($ScriptVal->"source" = "#!rsc by RouterOS\n") do={
$LogPrintExit2 warning $0 ("Failed fetching script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . \
"', removing dummy. Typo on installation?") false; "', removing dummy. Typo on installation?");
/system/script/remove $Script; /system/script/remove $Script;
} else={ } else={
$LogPrintExit2 warning $0 ("Failed fetching script '" . $ScriptVal->"name" . "'!") false; $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . "'!");
} }
} }
} }
@ -1046,7 +1046,7 @@
: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={ :if ([ $ValidateSyntax $SourceNew ] = true) do={
$LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false; $LogPrint info $0 ("Updating script: " . $ScriptVal->"name");
/system/script/set owner=($ScriptVal->"name") source=$SourceNew $Script; /system/script/set owner=($ScriptVal->"name") source=$SourceNew $Script;
:if ($ScriptVal->"name" = "global-config") do={ :if ($ScriptVal->"name" = "global-config") do={
:set ReloadGlobalConfig true; :set ReloadGlobalConfig true;
@ -1055,48 +1055,48 @@
:set ReloadGlobalFunctions true; :set ReloadGlobalFunctions true;
} }
} else={ } else={
$LogPrintExit2 warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Syntax validation for script '" . $ScriptVal->"name" . \
"' failed! Ignoring!") false; "' failed! Ignoring!");
} }
} else={ } else={
$LogPrintOnce warning $0 ("The script '" . $ScriptVal->"name" . "' requires RouterOS " . \ $LogPrintOnce warning $0 ("The script '" . $ScriptVal->"name" . "' requires RouterOS " . \
$Required . ", which is not met by your installation. Ignoring!"); $Required . ", which is not met by your installation. Ignoring!");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("Looks like new script '" . $ScriptVal->"name" . \ $LogPrint warning $0 ("Looks like new script '" . $ScriptVal->"name" . \
"' is not valid (missing shebang). Ignoring!") false; "' is not valid (missing shebang). Ignoring!");
} }
} else={ } else={
$LogPrintExit2 debug $0 ("Script '" . $ScriptVal->"name" . "' did not change.") false; $LogPrint debug $0 ("Script '" . $ScriptVal->"name" . "' did not change.");
} }
} else={ } else={
$LogPrintExit2 debug $0 ("No update for script '" . $ScriptVal->"name" . "'.") false; $LogPrint debug $0 ("No update for script '" . $ScriptVal->"name" . "'.");
} }
} }
:if ($ReloadGlobalFunctions = true) do={ :if ($ReloadGlobalFunctions = true) do={
$LogPrintExit2 info $0 ("Reloading global functions.") false; $LogPrint info $0 ("Reloading global functions.");
:do { :do {
/system/script/run global-functions; /system/script/run global-functions;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Reloading global functions failed!") false; $LogPrint error $0 ("Reloading global functions failed!");
} }
} }
:if ($ReloadGlobalConfig = true) do={ :if ($ReloadGlobalConfig = true) do={
$LogPrintExit2 info $0 ("Reloading global configuration.") false; $LogPrint info $0 ("Reloading global configuration.");
:do { :do {
/system/script/run global-config; /system/script/run global-config;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Reloading global configuration failed!" . \ $LogPrint error $0 ("Reloading global configuration failed!" . \
" Syntax error or missing overlay?") false; " Syntax error or missing overlay?");
} }
} }
:if ($ExpectedConfigVersionBefore > $ExpectedConfigVersion) do={ :if ($ExpectedConfigVersionBefore > $ExpectedConfigVersion) do={
$LogPrintExit2 warning $0 ("The configuration version decreased from " . \ $LogPrint warning $0 ("The configuration version decreased from " . \
$ExpectedConfigVersionBefore . " to " . $ExpectedConfigVersion . \ $ExpectedConfigVersionBefore . " to " . $ExpectedConfigVersion . \
". Installed an older version?") false; ". Installed an older version?");
} }
:if ($ExpectedConfigVersionBefore < $ExpectedConfigVersion) do={ :if ($ExpectedConfigVersionBefore < $ExpectedConfigVersion) do={
@ -1106,14 +1106,14 @@
:do { :do {
:local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix); :local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix);
$LogPrintExit2 debug $0 ("Fetching news, changes and migration: " . $Url) false; $LogPrint debug $0 ("Fetching news, changes and migration: " . $Url);
:local Result [ /tool/fetch check-certificate=yes-without-crl \ :local Result [ /tool/fetch check-certificate=yes-without-crl \
http-header-field=({ $FetchUserAgent }) $Url output=user as-value ]; http-header-field=({ $FetchUserAgent }) $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
:set ChangeLogCode ($Result->"data"); :set ChangeLogCode ($Result->"data");
} }
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed fetching news, changes and migration!") false; $LogPrint warning $0 ("Failed fetching news, changes and migration!");
} }
:if ([ :len $ChangeLogCode ] > 0) do={ :if ([ :len $ChangeLogCode ] > 0) do={
@ -1121,10 +1121,10 @@
:do { :do {
[ :parse $ChangeLogCode ]; [ :parse $ChangeLogCode ];
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("The changelog failed to run!") false; $LogPrint warning $0 ("The changelog failed to run!");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("The changelog failed syntax validation!") false; $LogPrint warning $0 ("The changelog failed syntax validation!");
} }
} }
@ -1133,14 +1133,14 @@
:local Migration ($GlobalConfigMigration->[ :tostr $I ]); :local Migration ($GlobalConfigMigration->[ :tostr $I ]);
:if ([ :typeof $Migration ] = "str") do={ :if ([ :typeof $Migration ] = "str") do={
:if ([ $ValidateSyntax $Migration ] = true) do={ :if ([ $ValidateSyntax $Migration ] = true) do={
$LogPrintExit2 info $0 ("Applying migration for change " . $I . ": " . $Migration) false; $LogPrint info $0 ("Applying migration for change " . $I . ": " . $Migration);
:do { :do {
[ :parse $Migration ]; [ :parse $Migration ];
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Migration code for change " . $I . " failed to run!") false; $LogPrint warning $0 ("Migration code for change " . $I . " failed to run!");
} }
} else={ } else={
$LogPrintExit2 warning $0 ("Migration code for change " . $I . " failed syntax validation!") false; $LogPrint warning $0 ("Migration code for change " . $I . " failed syntax validation!");
} }
} }
} }
@ -1149,7 +1149,7 @@
:local NotificationMessage ("The configuration version on " . $Identity . " increased " . \ :local NotificationMessage ("The configuration version on " . $Identity . " increased " . \
"to " . $ExpectedConfigVersion . ", current configuration may need modification. " . \ "to " . $ExpectedConfigVersion . ", current configuration may need modification. " . \
"Please review and update global-config-overlay, then re-run global-config."); "Please review and update global-config-overlay, then re-run global-config.");
$LogPrintExit2 info $0 ($NotificationMessage) false; $LogPrint info $0 ($NotificationMessage);
:if ([ :len $GlobalConfigChanges ] > 0) do={ :if ([ :len $GlobalConfigChanges ] > 0) do={
:set NotificationMessage ($NotificationMessage . "\n\nChanges:"); :set NotificationMessage ($NotificationMessage . "\n\nChanges:");
@ -1157,7 +1157,7 @@
:local Change ($GlobalConfigChanges->[ :tostr $I ]); :local Change ($GlobalConfigChanges->[ :tostr $I ]);
:set NotificationMessage ($NotificationMessage . "\n " . \ :set NotificationMessage ($NotificationMessage . "\n " . \
[ $SymbolForNotification "pushpin" "*" ] . $Change); [ $SymbolForNotification "pushpin" "*" ] . $Change);
$LogPrintExit2 info $0 ("Change " . $I . ": " . $Change) false; $LogPrint info $0 ("Change " . $I . ": " . $Change);
} }
} else={ } else={
:set NotificationMessage ($NotificationMessage . "\n\nNews and changes are not available."); :set NotificationMessage ($NotificationMessage . "\n\nNews and changes are not available.");
@ -1191,7 +1191,7 @@
:global GetRandom20CharAlNum; :global GetRandom20CharAlNum;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global ScriptLockOrder; :global ScriptLockOrder;
:if ([ :typeof $ScriptLockOrder ] = "nothing") do={ :if ([ :typeof $ScriptLockOrder ] = "nothing") do={
@ -1277,15 +1277,17 @@
} }
:if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={ :if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
$LogPrintExit2 error $0 ("A script named '" . $Script . "' does not exist!") true; $LogPrint error $0 ("A script named '" . $Script . "' does not exist!");
:error false;
} }
:if ([ $JobCount $Script ] = 0) do={ :if ([ $JobCount $Script ] = 0) do={
$LogPrintExit2 error $0 ("No script '" . $Script . "' is running!") true; $LogPrint error $0 ("No script '" . $Script . "' is running!");
:error false;
} }
:if ([ $TicketCount $Script ] >= [ $JobCount $Script ]) do={ :if ([ $TicketCount $Script ] >= [ $JobCount $Script ]) do={
$LogPrintExit2 error $0 ("More tickets than running scripts '" . $Script . "', resetting!") false; $LogPrint error $0 ("More tickets than running scripts '" . $Script . "', resetting!");
:set ($ScriptLockOrder->$Script) ({}); :set ($ScriptLockOrder->$Script) ({});
/system/script/job/remove [ find where script=$Script ]; /system/script/job/remove [ find where script=$Script ];
} }
@ -1306,8 +1308,8 @@
} }
$RemoveTicket $Script $MyTicket; $RemoveTicket $Script $MyTicket;
$LogPrintExit2 info $0 ("Script '" . $Script . "' started more than once" . [ $IfThenElse ($WaitCount > 0) \ $LogPrint info $0 ("Script '" . $Script . "' started more than once" . [ $IfThenElse ($WaitCount > 0) \
" and timed out waiting for lock" "" ] . "...") false; " and timed out waiting for lock" "" ] . "...");
:return false; :return false;
} }
@ -1542,10 +1544,10 @@
:do { :do {
/system/script/run $Script; /system/script/run $Script;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Module '" . $ScriptVal->"name" . "' failed to run.") false; $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run.");
} }
} else={ } else={
$LogPrintExit2 error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping.") false; $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping.");
} }
} }