aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'global-functions.rsc')
-rw-r--r--global-functions.rsc43
1 files changed, 27 insertions, 16 deletions
diff --git a/global-functions.rsc b/global-functions.rsc
index 66765bf..3800ad5 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -12,7 +12,7 @@
:local ScriptName [ :jobname ];
# expected configuration version
-:global ExpectedConfigVersion 127;
+:global ExpectedConfigVersion 128;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
@@ -230,11 +230,19 @@
:for I from=0 to=([ :len $Input ] - 1) do={
:local Char [ :pick $Input $I ];
:if ([ :typeof [ find "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-" $Char ] ] = "nil") do={
- :set Char "-";
- }
- :if ($Char != "-" || [ :pick $Return ([ :len $Return ] - 1) ] != "-") do={
- :set Return ($Return . $Char);
+ :do {
+ :if ([ :len $Return ] = 0) do={
+ :error true;
+ }
+ :if ([ :pick $Return ([ :len $Return ] - 1) ] = "-") do={
+ :error true;
+ }
+ :set Char "-";
+ } on-error={
+ :set Char "";
+ }
}
+ :set Return ($Return . $Char);
}
:return $Return;
}
@@ -406,13 +414,13 @@
:set CheckCert [ $IfThenElse ($CheckCert = false) "no" "yes-without-crl" ];
- :local FileName ("tmpfs/" . [ $CleanName $ScriptName ]);
- :if ([ $MkDir $FileName ] = false) do={
+ :local DirName ("tmpfs/" . [ $CleanName $ScriptName ]);
+ :if ([ $MkDir $DirName ] = false) do={
$LogPrint error $0 ("Failed creating directory!");
:return false;
}
- :set FileName ($FileName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]);
+ :local FileName ($DirName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]);
:do {
/tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \
http-header-field=({ [ $FetchUserAgentStr $ScriptName ] }) as-value;
@@ -421,6 +429,7 @@
/file/remove $FileName;
}
$LogPrint debug $0 ("Failed downloading from: " . $Url);
+ /file/remove $DirName;
:return false;
}
$WaitForFile $FileName;
@@ -432,7 +441,7 @@
:set Return ($Return . ([ /file/read offset=$VarSize chunk-size=32768 file=$FileName as-value ]->"data"));
:set VarSize [ :len $Return ];
}
- /file/remove $FileName;
+ /file/remove $DirName;
:return $Return;
}
@@ -664,7 +673,7 @@
:global IsTimeSyncCached;
:global IsTimeSyncResetNtp;
- :global LogPrint;
+ :global LogPrintOnce;
:if ($IsTimeSyncCached = true) do={
:return true;
@@ -676,14 +685,15 @@
:return true;
}
+ :local Uptime [ /system/resource/get uptime ];
:if ([ :typeof $IsTimeSyncResetNtp ] = "nothing") do={
- :set IsTimeSyncResetNtp 0s;
+ :set IsTimeSyncResetNtp $Uptime;
}
- :local Uptime [ /system/resource/get uptime ];
:if ($Uptime - $IsTimeSyncResetNtp < 3m) do={
:return false;
}
+ $LogPrintOnce warning $0 ("The ntp client is configured, but did not sync.");
:set IsTimeSyncResetNtp $Uptime;
/system/ntp/client/set enabled=no;
:delay 20ms;
@@ -693,7 +703,7 @@
:if ([ /system/license/get ]->"level" = "free" || \
[ /system/resource/get ]->"board-name" = "x86") do={
- $LogPrint debug $0 ("No ntp client configured, relying on RTC for CHR free license and x86.");
+ $LogPrintOnce debug $0 ("No ntp client configured, relying on RTC for CHR free license and x86.");
:return true;
}
@@ -705,7 +715,7 @@
:return false;
}
- $LogPrint debug $0 ("No time source configured! Returning gracefully...");
+ $LogPrintOnce debug $0 ("No time source configured! Returning gracefully...");
:return true;
}
@@ -1508,13 +1518,14 @@
:global CleanFilePath;
:global EitherOr;
+ :global MAX;
:set FileName [ $CleanFilePath $FileName ];
:local I 1;
- :local Delay ([ :totime [ $EitherOr $WaitTime 2s ] ] / 20);
+ :local Delay ([ $MAX [ $EitherOr $WaitTime 2s ] 100ms ] / 10);
:while ([ :len [ /file/find where name=$FileName ] ] = 0) do={
- :if ($I >= 20) do={
+ :if ($I >= 10) do={
:return false;
}
:delay $Delay;