aboutsummaryrefslogtreecommitdiffstats
path: root/check-routeros-update
blob: 0c39daa0d4db60fd97228656a6f3546755e5853d (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
53
54
55
56
57
58
59
#!rsc
# RouterOS script: check-routeros-update
# Copyright (c) 2013-2018 Christian Hesse <mail@eworm.de>
#
# check for RouterOS update, send notification e-mails

:global "identity";
:global "email-general-to";
:global "email-general-cc";
:global "safe-update-url";
:global "sent-routeros-update-notification";

:global SendNotification;

:if ([ :len [ / system package find where name="wireless" disabled=no ] ] > 0) do={
  :if ([ / interface wireless cap get enabled ] = true && \
      [ / caps-man manager get enabled ] = false) do={
    :error "System is managed by CAPsMAN, not checking.";
  }
}

/ system package update check-for-updates without-paging;
:local installedversion [ / system package update get installed-version ];
:local latestversion [ / system package update get latest-version ];

:if ($installedversion != $latestversion) do={
  :local channel [ / system package update get channel ];
  :local model [ / system routerboard get model ];
  :local serialnumber [ / system routerboard get serial-number ];

  :if ([ :len $"safe-update-url" ] > 0) do={
    :local result [ / tool fetch check-certificate=yes-without-crl \
        ($"safe-update-url" . $channel . "?installed=" . $installedversion . \
        "&latest=" . $latestversion) output=user as-value ];
    :if ($result->"status" = "finished" && $result->"data" = $latestversion) do={
      :log info ("Version " . $latestversion . " is assumed safe, updating...");
       $SendNotification ("[" . $identity . "] RouterOS update notification") \
         ("Version " . $latestversion . " is assumed safe for " . $channel . \
         ", updating on " . $identity . "...");
      / system package update install;
      :error "Waiting for system to reboot.";
    }
  }

  :if ($"sent-routeros-update-notification" = $latestversion) do={
    :error ("Already sent the RouterOS update notification for version " . \
        $latestversion . ".");
  }

  $SendNotification ("[" . $identity . "] RouterOS update notification") \
    ("There is a RouterOS update available\n\n" . \
      "Routerboard:   " . $model . "\n" . \
      "Serial number: " . $serialnumber . "\n" . \
      "Hostname:      " . $identity . "\n" . \
      "Channel:       " . $channel . "\n" . \
      "Installed:     " . $installedversion . "\n" . \
      "Available:     " . $latestversion);
  :set "sent-routeros-update-notification" $latestversion;
}