From a80591f51077130ddbaf88618b4c151c7a195e0f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 9 Jul 2018 22:59:16 +0200 Subject: script-updates: always accept updates from file --- global-config | 5 ++--- script-updates | 58 +++++++++++++++++++++++++--------------------------------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/global-config b/global-config index b71b0bd..e5750c6 100644 --- a/global-config +++ b/global-config @@ -38,12 +38,11 @@ :global "ntp-pool" "pool.ntp.org"; # Enable this to fetch scripts from given url. -:global "script-updates-fetch" false; +:global "script-updates-fetch" true; :global "script-updates-baseurl" "https://git.eworm.de/cgit.cgi/routeros-scripts/plain/"; #:global "script-updates-baseurl" "https://raw.githubusercontent.com/eworm-de/routeros-scripts/master/"; #:global "script-updates-baseurl" "https://gitlab.com/eworm-de/routeros-scripts/raw/master/"; -:global "script-updates-ignore" { "global-config"; "GeneratePSK" } -:global "script-updates-fetch-ignore" { "" }; +:global "script-updates-ignore" { "global-config"; "GeneratePSK" }; # Do *NOT* change these! :global "sent-routeros-update-notification" false; diff --git a/script-updates b/script-updates index 1f71278..3139274 100644 --- a/script-updates +++ b/script-updates @@ -6,49 +6,41 @@ :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) ]; - :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 ([ :len $scriptfile ] = 0 && $"script-updates-fetch" = true) do={ + :foreach "ignore-loop" in=$"script-updates-ignore" do={ + :if ($"ignore-loop" = $scriptname) do={ :set ignore 1; } + } - :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); - } + :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); } } + } - :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; + :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 debug ("No update for script " . $scriptname); + :log info ("Updating script: " . $scriptname); + / system script set owner=$scriptname source=$filecontent $script; } + / file remove $scriptfile; + } else={ + :log debug ("No update for script " . $scriptname); } } -- cgit v1.2.3-70-g09d2