routeros-scripts/check-routeros-update

58 lines
2.3 KiB
Text
Raw Normal View History

#!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";
:global "safe-update-url";
2018-07-05 13:29:26 +00:00
:global "sent-routeros-update-notification";
:global SendNotification;
:if ([ / system package print count-only where name="wireless" disabled=no ] > 0) do={
: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-07-05 13:29:26 +00:00
: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 ("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 ("RouterOS update notification") \
("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);
:set "sent-routeros-update-notification" $latestversion;
2018-07-05 13:29:26 +00:00
}