:global GlobalFuncReady false;
# Git commit id & info, expected configuration version
-:global CommitId "main/547/9b892c49";
+:global CommitId "main/548/b82d8221";
:global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 11:15:03 04.05.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 11:25:02 04.05.2026.";
# The variables are received right here.
:global GlobalConfVersion 140;
:local CheckCert [:tostr $3];
:local fetchMode [:tostr $4];
:local fetchMethod [:tostr $5];
+ :local FetchString "undefined";
+
:global CleanName;
:global FetchUserAgentStr;
:global GetRandom20CharAlNum;
:global WaitForFile;
:set CheckCert [ $IfThenElse ($CheckCert = "false") "no" "yes-without-crl" ];
+ #:set fetchMode [ $IfThenElse ($fetchMode != "false") [:tostr ("mode=" . $fetchMode)] ];
+ #:set fetchMethod [$IfThenElse ($fetchMethod != "false") [:tostr ("http-method=\"" . $fetchMethod . "\"") ]];
+
:local DirName ("tmpfs/" . [ $CleanName $FetchLargeScript ]);
:if ([ $MkDir $DirName ] = false) do={
- :log error ($FetchLargeScript . " Failed creating directory!");
+ $LogPrint error $0 ("Failed creating directory!");
:return false;
}
- :local FileName ($DirName . "/" . [ $CleanName $fetchUrl ] . "-" . [ $GetRandom20CharAlNum ]);
-
+ :local FileName ($DirName . "/" . [ $CleanName $FetchLargeScript ] . "-" . [ $GetRandom20CharAlNum ]); <-- ИСПРАВЛЕНО
:do {
- :if ($fetchMethod = "false") do={
- :if ($fetchMode = "false") do={
- /tool/fetch url=($fetchUrl) dst-path=$FileName check-certificate=$CheckCert http-header-field=({ [ $FetchUserAgentStr $FetchLargeScript ] }) as-value;
- } else={
- /tool/fetch url=($fetchUrl) dst-path=$FileName check-certificate=$CheckCert http-header-field=({ [ $FetchUserAgentStr $FetchLargeScript ] }) mode=$fetchMode as-value;
- }
- } else={
- :if ($fetchMode = "false") do={
- /tool/fetch url=($fetchUrl) dst-path=$FileName check-certificate=$CheckCert http-header-field=({ [ $FetchUserAgentStr $FetchLargeScript ] }) http-method=$fetchMethod as-value;
- } else={
- /tool/fetch url=($fetchUrl) dst-path=$FileName check-certificate=$CheckCert http-header-field=({ [ $FetchUserAgentStr $FetchLargeScript ] }) http-method=$fetchMethod mode=$fetchMode as-value;
- }
+ /tool/fetch check-certificate=$CheckCert mode=https http-header-field=({ [ $FetchUserAgentStr $FetchLargeScript ] }) \
+ url=("\" . $fetchUrl . "\"") dst-path=$FileName as-value;
+ } onerror Err {
+ :if ([ $WaitForFile $FileName 500ms ] = true) do={
+ $RmFile $FileName;
}
- } on-error={
- $LogPrint error $0 ("Failed downloading from " . $fetchUrl . " - " . $Err);
+ $LogPrint debug $0 ("Failed downloading from " . $fetchUrl . " - " . $Err);
$RmDir $DirName;
:return false;
}
-
:if ([ $WaitForFile $FileName 5s ] = false) do={
- $LogPrint error $0 ("The file downloaded from " . $fetchUrl . " did not show up.");
- $RmDir $DirName;
+ $LogPrint debug $0 ("The file downloaded from " . $fetchUrl . " did not show up.");
:return false;
}
-
:local FileSize [ /file/get $FileName size ];
:local Return "";
:local VarSize 0;
:if ([ :len [ /system/scheduler/find where name="AM-ScriptInstallUpdate" ] ] = 0) do={
/system/scheduler/add name="AM-ScriptInstallUpdate" comment=$Comment start-time=startup interval=1d on-event=$OnEvent;
}
+:do={
:log warning ("This script $ScriptName Loaded " . \
[ $IfThenElse ($CommitId != "unknown") ([ $CommitBrief ] . " ") ] . \
"on " . $devBoardName . "\nRouterOS: " . $devCurVersion . "\nArchitecture: " . $devCurArch . "\nIdentity: " . $Identity);
-
# signal we are ready
:set GlobalFuncReady true;
+} onerror Err {
+ :global ExitOnError; $ExitOnError $0 $Err;
+}