blob: 3d5dce9d50cbc6d8750edb44ad89ae8935be7a58 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!rsc by RouterOS
# RouterOS script: mod/scriptrunonece
# Copyright (c) 2020-2024 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# requires RouterOS, version=7.14
#
# download script and run it once
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mod/scriptrunonce.md
:global ScriptRunOnce;
# fetch and run script(s) once
:set ScriptRunOnce do={
:local Scripts [ :toarray $1 ];
:global ScriptRunOnceBaseUrl;
:global ScriptRunOnceUrlSuffix;
:global LogPrint;
:global ValidateSyntax;
:foreach Script in=$Scripts do={
:if (!($Script ~ "^(ftp|https?|sftp)://")) do={
:if ([ :len $ScriptRunOnceBaseUrl ] = 0) do={
$LogPrint warning $0 ("Script '" . $Script . "' is not an url and base url is not available.");
:return false;
}
: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={
$LogPrint warning $0 ("Failed fetching script '" . $Script . "'!");
}
:if ([ :len $Source ] > 0) do={
:if ([ $ValidateSyntax $Source ] = true) do={
:do {
$LogPrint info $0 ("Running script '" . $Script . "' now.");
[ :parse $Source ];
} on-error={
$LogPrint warning $0 ("The script '" . $Script . "' failed to run!");
}
} else={
$LogPrint warning $0 ("The script '" . $Script . "' failed syntax validation!");
}
}
}
}
|