aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-09-17 16:32:59 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-09-21 21:26:13 +0200
commit012db05a9350311ddac85a95e487d4fc0ebabcb6 (patch)
tree8487134ca76b6858b01fc3428db0adeb0486edd5
parent8b05d254871f5c04184aca6c992b1871fc8f98b8 (diff)
global-functions: move $ScriptRunOnce to optional module
-rw-r--r--global-config2
-rw-r--r--global-functions41
-rw-r--r--global-functions.d/scriptrunonce46
3 files changed, 48 insertions, 41 deletions
diff --git a/global-config b/global-config
index 98c65d9..6b2cd84 100644
--- a/global-config
+++ b/global-config
@@ -168,6 +168,8 @@
#:global ScriptUpdatesUrlSuffix "\?h=next";
# Use this for defaults with $ScriptRunOnce
+# Install module with:
+# $ScriptInstallUpdate global-functions.d/scriptrunonce
:global ScriptRunOnceBaseUrl "";
:global ScriptRunOnceUrlSuffix "";
diff --git a/global-functions b/global-functions
index 1a13588..e3340eb 100644
--- a/global-functions
+++ b/global-functions
@@ -43,7 +43,6 @@
:global ScriptFromTerminal;
:global ScriptInstallUpdate;
:global ScriptLock;
-:global ScriptRunOnce;
:global SendEMail;
:global SendEMail2;
:global SendNotification;
@@ -1000,46 +999,6 @@
: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;
diff --git a/global-functions.d/scriptrunonce b/global-functions.d/scriptrunonce
new file mode 100644
index 0000000..ce9425b
--- /dev/null
+++ b/global-functions.d/scriptrunonce
@@ -0,0 +1,46 @@
+#!rsc by RouterOS
+# RouterOS script: global-functions.d/scriptrunonece
+# Copyright (c) 2020-2021 Christian Hesse <mail@eworm.de>
+# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
+
+:global ScriptRunOnce;
+
+# 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;
+ }
+ }
+ }
+}