2021-09-17 14:32:59 +00:00
|
|
|
#!rsc by RouterOS
|
2021-11-15 19:22:56 +00:00
|
|
|
# RouterOS script: mod/scriptrunonece
|
2022-01-01 20:38:15 +00:00
|
|
|
# Copyright (c) 2020-2022 Christian Hesse <mail@eworm.de>
|
2021-09-17 14:32:59 +00:00
|
|
|
# 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 {
|
2022-05-10 14:14:02 +00:00
|
|
|
:set Source ([ /tool/fetch check-certificate=yes-without-crl $Script output=user as-value ]->"data");
|
2021-09-17 14:32:59 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|