:global GlobalFuncReady false;
# Git commit id & info, expected configuration version
-:global CommitId "main/530/33eda6b3";
+:global CommitId "main/531/01d7eb14";
:global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 08:45:02 04.05.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 08:55:02 04.05.2026.";
# The variables are received right here.
:global GlobalConfVersion 138;
:return $Return;
}
-# fetch huge data to file, read in chunks
-:set FetchHuge do={
- :local FetchScript [ :tostr $1 ];
- :local Url [ :tostr $2 ];
- :local CheckCert [ :tostr $3 ];
-
- :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" ];
-
- :local DirName ("tmpfs/" . [ $CleanName $FetchScript ]);
- :if ([ $MkDir $DirName ] = false) do={
- $LogPrint error $0 ("Failed creating directory!");
- :return false;
- }
-
- :local FileName ($DirName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]);
- :onerror Err {
- /tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \
- http-header-field=({ [ $FetchUserAgentStr $FetchScript ] }) as-value;
- } do={
- :if ([ $WaitForFile $FileName 500ms ] = true) do={
- $RmFile $FileName;
- }
- $LogPrint debug $0 ("Failed downloading from " . $Url . " - " . $Err);
- $RmDir $DirName;
- :return false;
- }
-
- :if ([ $WaitForFile $FileName 5s ] = false) do={
- $LogPrint debug $0 ("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;
- }
- }
- $RmDir $DirName;
- :return $Return;
-}
:set FetchUserAgentStr do={
:local Caller [ :tostr $1 ];
} do={:global ExitOnError; $ExitOnError $0 $Err}
}
-# Global Environment clear. Use: "$GlobalEnvRemove True;".
-:set GlobalEnvRemove do={
- :local doRmEnv [ :tostr $1 ];
- :global GlobalScriptsUrl;
- :local ScriptsUrl;
- :global LogPrint;
- :if ($doRmEnv != "True") do={
- $LogPrint error "GlobalEnvRemove" ("This script is needed \"True\" for confirm to remove global environment variables!");
- :return [];
- :error true;
- } else={
- :set ScriptsUrl $GlobalScriptsUrl;
- :delay 5;
- :foreach var in=[/system/script/environment print as-value] do={/system/script/environment remove ($var->".id")}
- :delay 5;
- :global GlobalScriptsUrl $ScriptsUrl;
- $LogPrint warning "GlobalEnvRemove" ("Done!");
- :return [];
- :error false;
- }
-}
-
# Add and fix global scheduler
:put "Add or/and fix Global scheduler...";
:local OnEvent "/system/script { run AM-GlobalConfig; run AM-GlobalFunc; }";