:global GlobalFuncReady false;
# Git commit id & info, expected configuration version
-:global CommitId "main/583/f681a0d3";
+:global CommitId "main/584/d376e295";
:global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 18:55:02 04.05.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 19:10:03 04.05.2026.";
# The variables are received right here.
:global GlobalConfVersion 140;
:global RequiredRouterOS;
:global ExitError;
:global ExitOnError;
-:global FetchLargeFiles;
+
:global FetchHugeFiles;
:global FetchUserAgentStr;
:global FileExists;
# "background-and-http-only", "background-and-no-redirects", "background-and-keep-broken-and-https-only", "background-and-keep-broken-and-http-only",
# "background-and-keep-broken-and-no-redirects")
# $5 - fetch method for /tool/fetch (optional, e.g. "get", "head", "post", "put", "patch", "delete")
-:set FetchLargeFiles do={
- :local RunName [:tostr $1];
- :local fetchUrl [:tostr $2];
- :local fetchFile [:tostr $3];
- :local CheckCert [:tostr $4];
- :local fetchMode [:tostr $5];
- :local fetchMethod [:tostr $6];
- :local tmpName;
- :global CleanName;
- :global FetchUserAgentStr;
- :global GetRandom20CharAlNum;
- :global IfThenElse;
- :global LogPrint;
- :global MkDir;
- :global RmDir;
- :global RmFile;
- :global WaitForFile;
-
- :set CheckCert [ $IfThenElse ($CheckCert = "false") "no" "yes-without-crl" ];
-
- :set tmpName ($CleanName "tmp-" . [ $GetRandom20CharAlNum 6 ]);
- :local DirName ("tmpfs/" . $tmpName);
- :if ([ $MkDir $DirName ] = false) do={
- :log error ($RunName . " Failed creating directory: " . $DirName . "!");
- :return false;
- }
-
- :local FileName ($DirName . "/" . [ $CleanName $fetchFile ] . "-" . [ $GetRandom20CharAlNum 5 ]);
- :local Url ($fetchUrl . $fetchFile);
- :onerror Err {
- /tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \
- http-header-field=({ [ $FetchUserAgentStr $RunName ] }) as-value;
- } do={
- :if ([ $WaitForFile $FileName 500ms ] = true) do={
- $RmFile $FileName;
- }
- :log error ($RunName . " Failed downloading from '" . $Url . "' - " . $Err);
- $RmDir $DirName;
- :return false;
- }
-
- :if ([ $WaitForFile $FileName 5s ] = false) do={
- :log error ($RunName . " The file downloaded from '" . $Url . "' did not show up.");
- :return false;
- }
-
- :local FileSize [ /file/get $FileName size ];
- :local Return "";
- :local VarSize 0;
- :while ($VarSize != $FileSize) do={
- :set Return ($Return . ([ /file/read offset=$VarSize chunk-size=32768 file=$FileName as-value ]->"data"));
- :set FileSize [ /file/get $FileName size ];
- :set VarSize [ :len $Return ];
- :if ($VarSize > $FileSize) do={
- :delay 100ms;
- }
- }
-# $RmFile $FileName;
- $RmDir $DirName;
- :return $Return;
-}
+#:set FetchLargeFiles do={
+# :local RunName [:tostr $1];
+# :local fetchUrl [:tostr $2];
+# :local fetchFile [:tostr $3];
+# :local CheckCert [:tostr $4];
+# :local fetchMode [:tostr $5];
+# :local fetchMethod [:tostr $6];
+# :local tmpName;
+# :global CleanName;
+# :global FetchUserAgentStr;
+# :global GetRandom20CharAlNum;
+# :global IfThenElse;
+# :global LogPrint;
+# :global MkDir;
+# :global RmDir;
+# :global RmFile;
+# :global WaitForFile;
+#
+# :set CheckCert [ $IfThenElse ($CheckCert = "false") "no" "yes-without-crl" ];
+#
+# :set tmpName ($CleanName "tmp-" . [ $GetRandom20CharAlNum 6 ]);
+# :local DirName ("tmpfs/" . $tmpName);
+# :if ([ $MkDir $DirName ] = false) do={
+# :log error ($RunName . " Failed creating directory: " . $DirName . "!");
+# :return false;
+# }
+#
+# :local FileName ($DirName . "/" . [ $CleanName $fetchFile ] . "-" . [ $GetRandom20CharAlNum 5 ]);
+# :local Url ($fetchUrl . $fetchFile);
+# :onerror Err {
+# /tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \
+# http-header-field=({ [ $FetchUserAgentStr $RunName ] }) as-value;
+# } do={
+# :if ([ $WaitForFile $FileName 500ms ] = true) do={
+# $RmFile $FileName;
+# }
+# :log error ($RunName . " Failed downloading from '" . $Url . "' - " . $Err);
+# $RmDir $DirName;
+# :return false;
+# }
+#
+# :if ([ $WaitForFile $FileName 5s ] = false) do={
+# :log error ($RunName . " The file downloaded from '" . $Url . "' did not show up.");
+# :return false;
+# }
+#
+# :local FileSize [ /file/get $FileName size ];
+# :local Return "";
+# :local VarSize 0;
+# :while ($VarSize != $FileSize) do={
+# :set Return ($Return . ([ /file/read offset=$VarSize chunk-size=32768 file=$FileName as-value ]->"data"));
+# :set FileSize [ /file/get $FileName size ];
+# :set VarSize [ :len $Return ];
+# :if ($VarSize > $FileSize) do={
+# :delay 100ms;
+# }
+# }
+## $RmFile $FileName;
+# $RmDir $DirName;
+# :return $Return;
+#}
:set ScriptInstallUpdate do={ :onerror Err {
:local Scripts [ :toarray $1 ];
:global ExitOnError; $ExitOnError $0 $Err;
} }
+# load modules
+:foreach Script in=[ /system/script/find where name ~ "^(global-functions\\.d|mod)/." ] do={
+ :local ScriptVal [ /system/script/get $Script ];
+ :if ([ $ValidateSyntax ($ScriptVal->"source") ] = true) do={
+ :onerror Err {
+ /system/script/run $Script;
+ } do={
+ $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run: " . $Err);
+ }
+ } else={
+ $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping.");
+ }
+}
+
# Add and fix global scheduler
:put "Add or/and fix Global scheduler...";
:local OnEvent "/system/script { run AM-GlobalConfig; run AM-GlobalFunc; }";