aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-07-09 22:05:45 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-07-10 23:18:04 +0200
commit483506b1898464366a30411a1f8ed336b508f870 (patch)
tree611ba7f62cb176e6ad691ab2b22513aa85c6ce8f /global-functions
parentd1ef710093eb6c747f8a54a0ec4355f5035aff4e (diff)
global-functions: introduce $ScriptRunOncechange-62
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions43
1 files changed, 42 insertions, 1 deletions
diff --git a/global-functions b/global-functions
index 47d70f1..1c20636 100644
--- a/global-functions
+++ b/global-functions
@@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version
-:global ExpectedConfigVersion 61;
+:global ExpectedConfigVersion 62;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
@@ -44,6 +44,7 @@
:global ScriptFromTerminal;
:global ScriptInstallUpdate;
:global ScriptLock;
+:global ScriptRunOnce;
:global SendEMail;
:global SendEMail2;
:global SendNotification;
@@ -991,6 +992,46 @@
:return true;
}
+# fetch and run script(s) once
+:set ScriptRunOnce do={
+ :local Scripts [ :toarray $1 ];
+
+ :global ScriptRunOnceBaseUrl;
+ :global ScriptRunOnceUrlSuffix;
+
+ :global LogPrintExit2;
+ :global ValidateSyntax;
+
+ :foreach Script in=$Scripts do={
+ :if (!($Script ~ "^(ftp|https\?|sftp)://")) do={
+ :if ([ :len $ScriptRunOnceBaseUrl ] = 0) do={
+ $LogPrintExit2 warning $0 ("Script '" . $Script . "' is not an url and base url is not available.") true;
+ }
+ :set Script ($ScriptRunOnceBaseUrl . $Script . $ScriptRunOnceUrlSuffix);
+ }
+
+ :local Source;
+ :do {
+ :set Source ([ / tool fetch check-certificate=yes-without-crl $Script output=user as-value ]->"data");
+ } on-error={
+ $LogPrintExit2 warning $0 ("Failed fetching script '" . $Script . "'!") false;
+ }
+
+ :if ([ :len $Source ] > 0) do={
+ :if ([ $ValidateSyntax $Source ] = true) do={
+ :do {
+ $LogPrintExit2 info $0 ("Running script '" . $Script . "' now.") false;
+ [ :parse $Source ];
+ } on-error={
+ $LogPrintExit2 warning $0 ("The script '" . $Script . "' failed to run!") false;
+ }
+ } else={
+ $LogPrintExit2 warning $0 ("The script '" . $Script . "' failed syntax validation!") false;
+ }
+ }
+ }
+}
+
# send notification via e-mail - expects at lease two string arguments
:set SendEMail do={
:global SendEMail2;