2018-08-24 14:16:56 +00:00
|
|
|
#
|
2018-07-05 13:29:26 +00:00
|
|
|
# RouterOS script: script-updates
|
|
|
|
# Copyright (c) 2013-2018 Christian Hesse <mail@eworm.de>
|
|
|
|
#
|
2018-07-09 14:05:04 +00:00
|
|
|
# update installed scripts from file or url
|
|
|
|
|
|
|
|
:global "script-updates-fetch";
|
|
|
|
:global "script-updates-baseurl";
|
|
|
|
:global "script-updates-ignore";
|
2018-07-05 13:29:26 +00:00
|
|
|
|
|
|
|
:foreach script in=[ / system script find ] do={
|
2018-07-09 14:05:04 +00:00
|
|
|
:local ignore 0;
|
2018-07-05 13:29:26 +00:00
|
|
|
:local scriptname [ / system script get $script name ];
|
2018-07-09 20:59:16 +00:00
|
|
|
:local scriptfile [ / file find where name=("script-updates/" . $scriptname) ];
|
2018-07-09 14:05:04 +00:00
|
|
|
|
2018-07-09 20:59:16 +00:00
|
|
|
:if ([ :len $scriptfile ] = 0 && $"script-updates-fetch" = true) do={
|
|
|
|
:foreach "ignore-loop" in=$"script-updates-ignore" do={
|
|
|
|
:if ($"ignore-loop" = $scriptname) do={ :set ignore 1; }
|
|
|
|
}
|
2018-07-09 14:05:04 +00:00
|
|
|
|
2018-07-09 20:59:16 +00:00
|
|
|
:if ($ignore = 0) do={
|
|
|
|
:log debug ("Fetching script from url: " . $scriptname);
|
|
|
|
:do {
|
|
|
|
/ tool fetch check-certificate=yes-without-crl \
|
|
|
|
dst-path=("script-updates/" . $scriptname) \
|
|
|
|
($"script-updates-baseurl" . $scriptname);
|
|
|
|
:set scriptfile [ / file find where name=("script-updates/" . $scriptname) ];
|
|
|
|
} on-error={
|
|
|
|
:log debug ("Failed fetching " . $scriptname);
|
2018-07-09 14:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-09 20:59:16 +00:00
|
|
|
}
|
2018-07-09 14:05:04 +00:00
|
|
|
|
2018-07-09 20:59:16 +00:00
|
|
|
:if ([ :len $scriptfile ] > 0) do={
|
|
|
|
:local filecontent [ / file get $scriptfile content ];
|
|
|
|
:local scriptsource [ / system script get $script source ];
|
|
|
|
:if ($filecontent = $scriptsource) do={
|
|
|
|
:log debug ("Script " . $scriptname . " did not change");
|
2018-07-09 14:05:04 +00:00
|
|
|
} else={
|
2018-07-09 20:59:16 +00:00
|
|
|
:log info ("Updating script: " . $scriptname);
|
|
|
|
/ system script set owner=$scriptname source=$filecontent $script;
|
2018-07-09 14:05:04 +00:00
|
|
|
}
|
2018-07-09 20:59:16 +00:00
|
|
|
/ file remove $scriptfile;
|
|
|
|
} else={
|
|
|
|
:log debug ("No update for script " . $scriptname);
|
2018-07-05 13:29:26 +00:00
|
|
|
}
|
|
|
|
}
|