From 5bacc4052a47d9c6da25b9302058f78d756b099c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 6 May 2025 19:42:12 +0200 Subject: [PATCH 1/3] global-functions: $ScriptInstallUpdate: set config and functions not ready... ... before reload. This should fix some corner cases where scripts ran with broken configuration or functions. Also do reload both - configuration and functions - to simplify the function. --- global-functions.rsc | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index 29e6d06b..6e3d7120 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1126,6 +1126,8 @@ :global CommitId; :global CommitInfo; :global ExpectedConfigVersion; + :global GlobalConfigReady; + :global GlobalFunctionsReady; :global Identity; :global IDonate; :global NoNewsAndChangesNotification; @@ -1159,8 +1161,7 @@ :local CommitIdBefore $CommitId; :local ExpectedConfigVersionBefore $ExpectedConfigVersion; - :local ReloadGlobalFunctions false; - :local ReloadGlobalConfig false; + :local ReloadGlobal false; :local DeviceMode [ /system/device-mode/get ]; :local CheckSums ({}); @@ -1269,31 +1270,25 @@ $LogPrint info $0 ("Updating script: " . $ScriptVal->"name"); /system/script/set owner=($ScriptVal->"name") \ source=[ $IfThenElse ($ScriptUpdatesCRLF = true) $SourceCRLF $SourceNew ] $Script; - :if ($ScriptVal->"name" = "global-config") do={ - :set ReloadGlobalConfig true; - } - :if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={ - :set ReloadGlobalFunctions true; + :if ($ScriptVal->"name" = "global-config" || \ + $ScriptVal->"name" = "global-functions" || \ + $ScriptVal->"name" ~ ("^mod/.")) do={ + :set ReloadGlobal true; } } on-error={ } } - :if ($ReloadGlobalFunctions = true) do={ - $LogPrint info $0 ("Reloading global functions."); - :do { - /system/script/run global-functions; - } on-error={ - $LogPrint error $0 ("Reloading global functions failed!"); - } - } + :if ($ReloadGlobal = true) do={ + $LogPrint info $0 ("Reloading global configuration and functions."); + :set GlobalConfigReady false; + :set GlobalFunctionsReady false; + :delay 1s; - :if ($ReloadGlobalConfig = true) do={ - $LogPrint info $0 ("Reloading global configuration."); - :do { + :onerror Err { /system/script/run global-config; - } on-error={ - $LogPrint error $0 ("Reloading global configuration failed!" . \ - " Syntax error or missing overlay?"); + /system/script/run global-functions; + } do={ + $LogPrint error $0 ("Reloading global configuration and functions failed! " . $Err); } } From 2eb3d4d533da6b25b6a99ea6580dd42251d9ea9a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 May 2025 11:45:55 +0200 Subject: [PATCH 2/3] sms-forward: delay after removal... ... to give the SIM card some time to succeed. Removing several messages one after another fails without this. --- sms-forward.rsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sms-forward.rsc b/sms-forward.rsc index 8ca5ae43..1bf312f6 100644 --- a/sms-forward.rsc +++ b/sms-forward.rsc @@ -62,6 +62,7 @@ ($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={ $LogPrint debug $ScriptName ("Removing SMS, which started a script."); /tool/sms/inbox/remove $Sms; + :delay 300ms; } else={ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ " type " . $SmsVal->"type" . ":\n" . $SmsVal->"message"); @@ -93,6 +94,7 @@ " by " . $Identity . " from " . $Phone . ":" . $Messages) }); :foreach Sms in=$Delete do={ /tool/sms/inbox/remove $Sms; + :delay 300ms; } } } From 8fc75e00c4725a206723e3385ae5199f3a2c6110 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 May 2025 14:31:37 +0200 Subject: [PATCH 3/3] sms-forward: add error handling on message removal --- sms-forward.rsc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sms-forward.rsc b/sms-forward.rsc index 1bf312f6..df5373d4 100644 --- a/sms-forward.rsc +++ b/sms-forward.rsc @@ -61,8 +61,12 @@ :if ($Phone = $Settings->"allowed-number" && \ ($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={ $LogPrint debug $ScriptName ("Removing SMS, which started a script."); - /tool/sms/inbox/remove $Sms; - :delay 300ms; + :onerror Err { + /tool/sms/inbox/remove $Sms; + :delay 300ms; + } do={ + $LogPrint warning $ScriptName ("Failed to remove message: " . $Err); + } } else={ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ " type " . $SmsVal->"type" . ":\n" . $SmsVal->"message"); @@ -93,8 +97,12 @@ message=("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \ " by " . $Identity . " from " . $Phone . ":" . $Messages) }); :foreach Sms in=$Delete do={ - /tool/sms/inbox/remove $Sms; - :delay 300ms; + :onerror Err { + /tool/sms/inbox/remove $Sms; + :delay 300ms; + } do={ + $LogPrint warning $ScriptName ("Failed to remove message: " . $Err); + } } } }