2018-09-26 22:18:43 +00:00
|
|
|
#!rsc
|
2018-07-05 13:29:26 +00:00
|
|
|
# RouterOS script: check-routeros-update
|
2019-01-01 20:19:19 +00:00
|
|
|
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
|
2018-07-05 13:29:26 +00:00
|
|
|
#
|
|
|
|
# check for RouterOS update, send notification e-mails
|
|
|
|
|
|
|
|
:global "identity";
|
2018-08-30 09:26:47 +00:00
|
|
|
:global "safe-update-url";
|
2018-07-05 13:29:26 +00:00
|
|
|
:global "sent-routeros-update-notification";
|
|
|
|
|
2018-10-09 13:53:27 +00:00
|
|
|
:global SendNotification;
|
|
|
|
|
2018-11-09 20:37:19 +00:00
|
|
|
:if ([ / system package print count-only where name="wireless" disabled=no ] > 0) do={
|
2018-07-09 18:41:31 +00:00
|
|
|
:if ([ / interface wireless cap get enabled ] = true && \
|
|
|
|
[ / caps-man manager get enabled ] = false) do={
|
2018-07-05 13:29:26 +00:00
|
|
|
: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 ];
|
2018-08-30 06:18:17 +00:00
|
|
|
|
2018-07-05 13:29:26 +00:00
|
|
|
:if ($installedversion != $latestversion) do={
|
2018-08-30 06:18:17 +00:00
|
|
|
:local channel [ / system package update get channel ];
|
|
|
|
:local model [ / system routerboard get model ];
|
|
|
|
:local serialnumber [ / system routerboard get serial-number ];
|
|
|
|
|
2018-08-30 09:26:47 +00:00
|
|
|
:if ([ :len $"safe-update-url" ] > 0) do={
|
|
|
|
:local result [ / tool fetch check-certificate=yes-without-crl \
|
2018-09-19 20:18:42 +00:00
|
|
|
($"safe-update-url" . $channel . "?installed=" . $installedversion . \
|
|
|
|
"&latest=" . $latestversion) output=user as-value ];
|
2018-08-30 09:26:47 +00:00
|
|
|
:if ($result->"status" = "finished" && $result->"data" = $latestversion) do={
|
|
|
|
:log info ("Version " . $latestversion . " is assumed safe, updating...");
|
2018-11-27 13:08:14 +00:00
|
|
|
$SendNotification ("RouterOS update notification") \
|
2018-10-10 10:49:03 +00:00
|
|
|
("Version " . $latestversion . " is assumed safe for " . $channel . \
|
|
|
|
", updating on " . $identity . "...");
|
2018-08-30 09:26:47 +00:00
|
|
|
/ system package update install;
|
|
|
|
:error "Waiting for system to reboot.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
:if ($"sent-routeros-update-notification" = $latestversion) do={
|
2018-09-20 18:33:19 +00:00
|
|
|
:error ("Already sent the RouterOS update notification for version " . \
|
|
|
|
$latestversion . ".");
|
2018-08-30 09:26:47 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 13:08:14 +00:00
|
|
|
$SendNotification ("RouterOS update notification") \
|
2018-10-09 13:53:27 +00:00
|
|
|
("There is a RouterOS update available\n\n" . \
|
2018-07-05 13:29:26 +00:00
|
|
|
"Routerboard: " . $model . "\n" . \
|
|
|
|
"Serial number: " . $serialnumber . "\n" . \
|
|
|
|
"Hostname: " . $identity . "\n" . \
|
|
|
|
"Channel: " . $channel . "\n" . \
|
|
|
|
"Installed: " . $installedversion . "\n" . \
|
|
|
|
"Available: " . $latestversion);
|
2018-08-30 06:18:17 +00:00
|
|
|
:set "sent-routeros-update-notification" $latestversion;
|
2018-07-05 13:29:26 +00:00
|
|
|
}
|