2018-08-24 14:16:56 +00:00
|
|
|
#
|
2018-07-05 13:29:26 +00:00
|
|
|
# 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";
|
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-07-09 18:41:31 +00:00
|
|
|
: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={
|
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...");
|
|
|
|
/ 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 . ".");
|
|
|
|
}
|
|
|
|
|
2018-07-05 13:29:26 +00:00
|
|
|
/ tool e-mail send to=$"email-general-to" cc=$"email-general-cc" \
|
|
|
|
subject=("[" . $identity . "] RouterOS update notification") \
|
|
|
|
body=("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);
|
2018-08-30 06:18:17 +00:00
|
|
|
:set "sent-routeros-update-notification" $latestversion;
|
2018-07-05 13:29:26 +00:00
|
|
|
}
|