aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2022-03-28 13:36:11 +0200
committerGravatar Christian Hesse <mail@eworm.de>2022-03-30 17:31:53 +0200
commit58f5a4fced9c35b4f3a5e25bebbac72e0a2c943a (patch)
tree4f1ceb7f80953bba09f83696f38f16d0866ba0cc
parent1cddf5590de5f410a0b7ec00d5323bbfe25c47a1 (diff)
check-lte-firmware-upgrade: rework code and its logic
(cherry picked from commit 2aa93a06716350d5e29fff4cfd1e7deb338ab80c)
-rw-r--r--check-lte-firmware-upgrade101
1 files changed, 59 insertions, 42 deletions
diff --git a/check-lte-firmware-upgrade b/check-lte-firmware-upgrade
index d861784..5f6bb69 100644
--- a/check-lte-firmware-upgrade
+++ b/check-lte-firmware-upgrade
@@ -10,56 +10,73 @@
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
-:global Identity;
:global SentLteFirmwareUpgradeNotification;
-:global CharacterReplace;
-:global LogPrintExit2;
-:global ScriptFromTerminal;
-:global SendNotification2;
-:global SymbolForNotification;
+:if ([ :typeof $SentLteFirmwareUpgradeNotification ] != "array") do={
+ :global SentLteFirmwareUpgradeNotification [ :toarray "" ];
+}
-:foreach Interface in=[ / interface lte find ] do={
- :local IntName [ / interface lte get $Interface name ];
- :do {
- :local Firmware [ / interface lte firmware-upgrade $Interface once as-value ];
- :local Info [ / interface lte info $Interface once as-value ];
+:local CheckInterface do={
+ :local Interface $1;
- :if ($SentLteFirmwareUpgradeNotification = ($Firmware->"latest")) do={
- $LogPrintExit2 debug $0 ("Already sent the LTE firmware upgrade notification for version " . \
- ($Firmware->"latest") . ".") false;
- } else={
- :if (($Firmware->"installed") != ($Firmware->"latest")) do={
- $LogPrintExit2 info $0 ("A new firmware version " . ($Firmware->"latest") . " is available for " . \
- "LTE interface " . $IntName . ".") false;
+ :global Identity;
+ :global SentLteFirmwareUpgradeNotification;
- :if ([ $ScriptFromTerminal $0 ] = true && \
- [ :len [ / system script find where name="unattended-lte-firmware-upgrade" ] ] > 0) do={
- :put ("Do you want to start unattended lte firmware upgrade for interface " . $IntName . "? [y/N]");
- :if (([ / terminal inkey timeout=60 ] % 32) = 25) do={
- / system script run unattended-lte-firmware-upgrade;
- $LogPrintExit2 info $0 ("Scheduled lte firmware upgrade for interface " . $IntName . "...") true;
- } else={
- :put "Canceled...";
- }
- }
+ :global CharacterReplace;
+ :global LogPrintExit2;
+ :global ScriptFromTerminal;
+ :global SendNotification2;
+ :global SymbolForNotification;
- $SendNotification2 ({ origin=$0; \
- subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \
- message=("A new firmware version " . ($Firmware->"latest") . " is available for " . \
- "LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \
- "Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \
- "Installed: " . ($Firmware->"installed") . "\n" . \
- "Available: " . ($Firmware->"latest")); silent=true });
- :set SentLteFirmwareUpgradeNotification ($Firmware->"latest");
- } else={
- :if ([ $ScriptFromTerminal $0 ] = true) do={
- $LogPrintExit2 info $0 ("No firmware upgrade available for LTE interface " . $IntName . ".") false;
- }
- }
- }
+ :local IntName [ / interface lte get $Interface name ];
+ :local Firmware;
+ :local Info;
+ :do {
+ :set Firmware [ / interface lte firmware-upgrade $Interface once as-value ];
+ :set Info [ / interface lte info $Interface once as-value ];
} on-error={
$LogPrintExit2 debug $0 ("Could not get latest LTE firmware version for interface " . \
$IntName . ".") false;
+ :return false;
+ }
+
+ :if (($Firmware->"installed") = ($Firmware->"latest")) do={
+ :if ([ $ScriptFromTerminal "check-lte-firmware-upgrade" ] = true) do={
+ $LogPrintExit2 info $0 ("No firmware upgrade available for LTE interface " . $IntName . ".") false;
+ }
+ :return true;
}
+
+ :if ([ $ScriptFromTerminal "check-lte-firmware-upgrade" ] = true && \
+ [ :len [ / system script find where name="unattended-lte-firmware-upgrade" ] ] > 0) do={
+ :put ("Do you want to start unattended lte firmware upgrade for interface " . $IntName . "? [y/N]");
+ :if (([ / terminal inkey timeout=60 ] % 32) = 25) do={
+ / system script run unattended-lte-firmware-upgrade;
+ $LogPrintExit2 info $0 ("Scheduled lte firmware upgrade for interface " . $IntName . "...") false;
+ :return true;
+ } else={
+ :put "Canceled...";
+ }
+ }
+
+ :if (($SentLteFirmwareUpgradeNotification->$IntName) = ($Firmware->"latest")) do={
+ $LogPrintExit2 debug $0 ("Already sent the LTE firmware upgrade notification for version " . \
+ ($Firmware->"latest") . ".") false;
+ :return false;
+ }
+
+ $LogPrintExit2 info $0 ("A new firmware version " . ($Firmware->"latest") . " is available for " . \
+ "LTE interface " . $IntName . ".") false;
+ $SendNotification2 ({ origin=$0; \
+ subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \
+ message=("A new firmware version " . ($Firmware->"latest") . " is available for " . \
+ "LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \
+ "Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \
+ "Installed: " . ($Firmware->"installed") . "\n" . \
+ "Available: " . ($Firmware->"latest")); silent=true });
+ :set ($SentLteFirmwareUpgradeNotification->$IntName) ($Firmware->"latest");
+}
+
+:foreach Interface in=[ / interface lte find ] do={
+ $CheckInterface $Interface;
}