mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
71ad56aacc
Copyright (C) 2013-2020 Christian Hesse <mail@eworm.de> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. https://www.gnu.org/licenses/#GPL https://www.gnu.org/licenses/gpl.html https://www.gnu.org/licenses/gpl.md
85 lines
3.2 KiB
Text
85 lines
3.2 KiB
Text
#!rsc
|
|
# RouterOS script: check-routeros-update
|
|
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
|
#
|
|
# check for RouterOS update, send notification and/or install
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/check-routeros-update.md
|
|
|
|
:global Identity;
|
|
:global SafeUpdateUrl;
|
|
:global SentRouterosUpdateNotification;
|
|
|
|
:global DeviceInfo;
|
|
:global LogPrintExit;
|
|
:global ScriptFromTerminal;
|
|
:global SendNotification;
|
|
|
|
:local DoUpdate do={
|
|
:if ([ / system script print count-only where name="packages-update" ] > 0) do={
|
|
/ system script run packages-update;
|
|
} else={
|
|
/ system package update install without-paging;
|
|
}
|
|
:error "Waiting for system to reboot.";
|
|
}
|
|
|
|
: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={
|
|
$LogPrintExit error "System is managed by CAPsMAN, not checking." true;
|
|
}
|
|
}
|
|
|
|
:if ([ / system scheduler print count-only where name="reboot-for-update" ] > 0) do={
|
|
:error "A reboot for update is already scheduled.";
|
|
}
|
|
|
|
/ system package update check-for-updates without-paging;
|
|
:local Update [ / system package update get ];
|
|
|
|
:if ([ :len ($Update->"latest-version") ] = 0) do={
|
|
$LogPrintExit warning "An empty string is not a valid version." true;
|
|
}
|
|
|
|
:if ($Update->"installed-version" != $Update->"latest-version") do={
|
|
:if ([ :len $SafeUpdateUrl ] > 0) do={
|
|
:local Result;
|
|
:do {
|
|
:set Result [ / tool fetch check-certificate=yes-without-crl \
|
|
($SafeUpdateUrl . $Update->"channel" . "?installed=" . $Update->"installed-version" . \
|
|
"&latest=" . $Update->"latest-version") output=user as-value ];
|
|
} on-error={
|
|
$LogPrintExit warning ("Failed receiving safe version for " . $Update->"channel" . ".") false;
|
|
}
|
|
:if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={
|
|
$LogPrintExit info ("Version " . $Update->"latest-version" . " is considered safe, updating...") false;
|
|
$SendNotification ("RouterOS update") \
|
|
("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \
|
|
", updating on " . $Identity . "...") "" "true";
|
|
$DoUpdate;
|
|
}
|
|
}
|
|
|
|
:if ([ $ScriptFromTerminal "check-routeros-update" ] = true) do={
|
|
:put ("Do you want to install RouterOS version " . $Update->"latest-version" . "? [y/N]");
|
|
:if (([ :terminal inkey timeout=60 ] % 32) = 25) do={
|
|
$DoUpdate;
|
|
} else={
|
|
:put "Canceled...";
|
|
}
|
|
}
|
|
|
|
:if ($SentRouterosUpdateNotification = $Update->"latest-version") do={
|
|
$LogPrintExit info ("Already sent the RouterOS update notification for version " . \
|
|
$Update->"latest-version" . ".") true;
|
|
}
|
|
|
|
$SendNotification ("RouterOS update \E2\9C\A8") \
|
|
("A new RouterOS version " . ($Update->"latest-version") . \
|
|
" is available for " . $Identity . ".\n\n" . \
|
|
[ $DeviceInfo ] . "\n\n" . \
|
|
"https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree") \
|
|
"" "true";
|
|
:set SentRouterosUpdateNotification ($Update->"latest-version");
|
|
}
|