aboutsummaryrefslogtreecommitdiffstats
path: root/script-updates
blob: ffa8da49d1875fc1d486294eb030f267eb2c06b9 (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
# RouterOS script: script-updates
# Copyright (c) 2013-2018 Christian Hesse <mail@eworm.de>
#
# 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 ];

  :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);
    }
  }
}