2023-03-07 09:57:42 +00:00
|
|
|
#!rsc by RouterOS
|
|
|
|
# RouterOS script: mod/scriptrunonece
|
2024-01-01 14:25:25 +00:00
|
|
|
# Copyright (c) 2020-2024 Christian Hesse <mail@eworm.de>
|
2023-03-07 09:57:42 +00:00
|
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
2023-04-04 17:24:00 +00:00
|
|
|
#
|
|
|
|
# download script and run it once
|
|
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mod/scriptrunonce.md
|
2023-03-07 09:57:42 +00:00
|
|
|
|
|
|
|
:global ScriptRunOnce;
|
|
|
|
|
|
|
|
# fetch and run script(s) once
|
|
|
|
:set ScriptRunOnce do={
|
|
|
|
:local Scripts [ :toarray $1 ];
|
|
|
|
|
|
|
|
:global ScriptRunOnceBaseUrl;
|
|
|
|
:global ScriptRunOnceUrlSuffix;
|
|
|
|
|
2024-03-08 11:45:38 +00:00
|
|
|
:global LogPrint;
|
2023-03-07 09:57:42 +00:00
|
|
|
:global ValidateSyntax;
|
|
|
|
|
|
|
|
:foreach Script in=$Scripts do={
|
2023-06-26 09:17:24 +00:00
|
|
|
:if (!($Script ~ "^(ftp|https?|sftp)://")) do={
|
2023-03-07 09:57:42 +00:00
|
|
|
:if ([ :len $ScriptRunOnceBaseUrl ] = 0) do={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint warning $0 ("Script '" . $Script . "' is not an url and base url is not available.");
|
|
|
|
:error false;
|
2023-03-07 09:57:42 +00:00
|
|
|
}
|
|
|
|
:set Script ($ScriptRunOnceBaseUrl . $Script . ".rsc" . $ScriptRunOnceUrlSuffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
:local Source;
|
|
|
|
:do {
|
|
|
|
:set Source ([ /tool/fetch check-certificate=yes-without-crl $Script output=user as-value ]->"data");
|
|
|
|
} on-error={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint warning $0 ("Failed fetching script '" . $Script . "'!");
|
2023-03-07 09:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
:if ([ :len $Source ] > 0) do={
|
|
|
|
:if ([ $ValidateSyntax $Source ] = true) do={
|
|
|
|
:do {
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint info $0 ("Running script '" . $Script . "' now.");
|
2023-03-07 09:57:42 +00:00
|
|
|
[ :parse $Source ];
|
|
|
|
} on-error={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint warning $0 ("The script '" . $Script . "' failed to run!");
|
2023-03-07 09:57:42 +00:00
|
|
|
}
|
|
|
|
} else={
|
2024-03-08 11:45:38 +00:00
|
|
|
$LogPrint warning $0 ("The script '" . $Script . "' failed syntax validation!");
|
2023-03-07 09:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|