mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
global-functions: introduce $ScriptRunOnce
This commit is contained in:
parent
d1ef710093
commit
483506b189
4 changed files with 49 additions and 3 deletions
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
:global GlobalConfigVersion 61;
|
:global GlobalConfigVersion 62;
|
||||||
|
|
||||||
# This is used for DNS and backup file.
|
# This is used for DNS and backup file.
|
||||||
:global Domain "example.com";
|
:global Domain "example.com";
|
||||||
|
@ -167,6 +167,10 @@
|
||||||
# use next branch with default url (git.eworm.de)
|
# use next branch with default url (git.eworm.de)
|
||||||
#:global ScriptUpdatesUrlSuffix "\?h=next";
|
#:global ScriptUpdatesUrlSuffix "\?h=next";
|
||||||
|
|
||||||
|
# Use this for defaults with $ScriptRunOnce
|
||||||
|
:global ScriptRunOnceBaseUrl "";
|
||||||
|
:global ScriptRunOnceUrlSuffix "";
|
||||||
|
|
||||||
# This project is developed in private spare time and usage is free of charge
|
# This project is developed in private spare time and usage is free of charge
|
||||||
# for you. If you like the scripts and think this is of value for you or your
|
# for you. If you like the scripts and think this is of value for you or your
|
||||||
# business please consider a donation:
|
# business please consider a donation:
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
# Comment or remove to disable news and change notifications.
|
# Comment or remove to disable news and change notifications.
|
||||||
:global GlobalConfigVersion 61;
|
:global GlobalConfigVersion 62;
|
||||||
|
|
||||||
# Copy configuration from global-config here and modify it.
|
# Copy configuration from global-config here and modify it.
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
59="Updating CAP with 'check-routeros-update' is now possible with opt-in.";
|
59="Updating CAP with 'check-routeros-update' is now possible with opt-in.";
|
||||||
60="Implemented a pre-down hook in 'netwatch-notify' that fires at two thirds of failed checks.";
|
60="Implemented a pre-down hook in 'netwatch-notify' that fires at two thirds of failed checks.";
|
||||||
61="Finally removed old scripts.";
|
61="Finally removed old scripts.";
|
||||||
|
62="Added '\$ScriptRunOnce' to run a script from URL once without installation, intended to aid configuration management and the like.";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Migration steps to be applied on script updates
|
# Migration steps to be applied on script updates
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/
|
# https://git.eworm.de/cgit/routeros-scripts/about/
|
||||||
|
|
||||||
# expected configuration version
|
# expected configuration version
|
||||||
:global ExpectedConfigVersion 61;
|
:global ExpectedConfigVersion 62;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
@ -44,6 +44,7 @@
|
||||||
:global ScriptFromTerminal;
|
:global ScriptFromTerminal;
|
||||||
:global ScriptInstallUpdate;
|
:global ScriptInstallUpdate;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
|
:global ScriptRunOnce;
|
||||||
:global SendEMail;
|
:global SendEMail;
|
||||||
:global SendEMail2;
|
:global SendEMail2;
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
|
@ -991,6 +992,46 @@
|
||||||
:return true;
|
: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
|
# send notification via e-mail - expects at lease two string arguments
|
||||||
:set SendEMail do={
|
:set SendEMail do={
|
||||||
:global SendEMail2;
|
:global SendEMail2;
|
||||||
|
|
Loading…
Reference in a new issue