aboutsummaryrefslogtreecommitdiffstats
path: root/script-updates
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2018-07-09 16:05:04 +0200
committerGravatar Christian Hesse <mail@eworm.de>2018-07-09 16:05:04 +0200
commit56e641a980a184b76914f8808793b7e952cdf76e (patch)
tree229f85fd412de28c505584c28417b289362181d9 /script-updates
parent9d498a60bd30611457b7b77d43173bf0384cce70 (diff)
script-updates: support fetch from url
Diffstat (limited to 'script-updates')
-rw-r--r--script-updates49
1 files changed, 40 insertions, 9 deletions
diff --git a/script-updates b/script-updates
index 13480d1..ffa8da4 100644
--- a/script-updates
+++ b/script-updates
@@ -1,17 +1,48 @@
# RouterOS script: script-updates
# Copyright (c) 2013-2018 Christian Hesse <mail@eworm.de>
#
-# update installed scripts from file
+# update installed scripts from file or url
+
+:global "script-updates-fetch";
+:global "script-updates-baseurl";
+:global "script-updates-ignore";
+:global "script-updates-fetch-ignore";
:foreach script in=[ / system script find ] do={
+ :local ignore 0;
:local scriptname [ / system script get $script name ];
- :local scriptfile [ / file find where name=("script-updates/" . $scriptname) ];
- :if ([ :len $scriptfile ] > 0) do={
- :log info ("Updating script: " . $scriptname);
- :local scriptcontent [ / file get $scriptfile content ];
- / system script set owner=$scriptname source=$scriptcontent $script;
- / file remove $scriptfile;
- } else={
- :log debug ("No update for script " . $scriptname);
+
+ :foreach "ignore-loop" in=$"script-updates-ignore" do={
+ :if ($"ignore-loop" = $scriptname) do={ :set ignore 1; }
+ }
+
+ :if ($ignore = 0) do={
+ :local scriptfile [ / file find where name=("script-updates/" . $scriptname) ];
+
+ :if ([ :len $scriptfile ] = 0 && $"script-updates-fetch" = true) do={
+ :foreach "ignore-loop" in=$"script-updates-fetch-ignore" do={
+ :if ($"ignore-loop" = $scriptname) do={ :set ignore 1; }
+ }
+
+ :if ($ignore = 0) do={
+ :log debug ("Fetching script from url: " . $scriptname);
+ / tool fetch dst-path=("script-updates/" . $scriptname) ($"script-updates-baseurl" . $scriptname);
+ :set scriptfile [ / file find where name=("script-updates/" . $scriptname) ];
+ }
+ }
+
+ :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");
+ } else={
+ :log info ("Updating script: " . $scriptname);
+ / system script set owner=$scriptname source=$filecontent $script;
+ }
+ / file remove $scriptfile;
+ } else={
+ :log debug ("No update for script " . $scriptname);
+ }
}
}