mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
08ef63ddbd
The old link was delivered with MIME type 'application/octet-stream', browsers wanted to download it as file.
84 lines
3.1 KiB
Text
84 lines
3.1 KiB
Text
#!rsc
|
|
# RouterOS script: check-routeros-update
|
|
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
|
|
#
|
|
# check for RouterOS update, send notification and/or install
|
|
|
|
:global Identity;
|
|
:global SafeUpdateUrl;
|
|
:global SentRouterosUpdateNotification;
|
|
|
|
:global SendNotification;
|
|
|
|
:local Update 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={
|
|
:log warning "System is managed by CAPsMAN, not checking.";
|
|
:error "Warning: See log for details.";
|
|
}
|
|
}
|
|
|
|
/ 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 BoardName [ / system resource get board-name ];
|
|
:local Model [ / system routerboard get model ];
|
|
:local SerialNumber [ / system routerboard get serial-number ];
|
|
|
|
:if ([ :len $SafeUpdateUrl ] > 0) do={
|
|
:local Result;
|
|
:do {
|
|
:set Result [ / tool fetch check-certificate=yes-without-crl \
|
|
($SafeUpdateUrl . $Channel . "?installed=" . $InstalledVersion . \
|
|
"&latest=" . $LatestVersion) output=user as-value ];
|
|
} on-error={
|
|
:log warning ("Failed receiving safe version for " . $Channel . ".");
|
|
}
|
|
:if ($Result->"status" = "finished" && $Result->"data" = $LatestVersion) do={
|
|
:log info ("Version " . $LatestVersion . " is considered safe, updating...");
|
|
$SendNotification ("RouterOS update") \
|
|
("Version " . $LatestVersion . " is considered safe for " . $Channel . \
|
|
", updating on " . $Identity . "...");
|
|
$Update;
|
|
}
|
|
}
|
|
|
|
:if ([ / system script job print count-only where script="check-routeros-update" parent~"." ] > 0) do={
|
|
:put ("Do you want to install RouterOS version " . $LatestVersion . "? [y/N]");
|
|
:if ([ :terminal inkey timeout=60 ] = 121) do={
|
|
$Update;
|
|
} else={
|
|
:put "Canceled...";
|
|
}
|
|
}
|
|
|
|
:if ($SentRouterosUpdateNotification = $LatestVersion) do={
|
|
:log info ("Already sent the RouterOS update notification for version " . \
|
|
$LatestVersion . ".");
|
|
:error "Already sent notification.";
|
|
}
|
|
|
|
$SendNotification ("RouterOS update") \
|
|
("There is a RouterOS update available.\n\n" . \
|
|
"Board name: " . $BoardName . "\n" . \
|
|
"Model: " . $Model . "\n" . \
|
|
"Serial number: " . $SerialNumber . "\n" . \
|
|
"Hostname: " . $Identity . "\n" . \
|
|
"Channel: " . $Channel . "\n" . \
|
|
"Installed: " . $InstalledVersion . "\n" . \
|
|
"Available: " . $LatestVersion . "\n\n" .\
|
|
"https://mikrotik.com/download/changelogs/" . $Channel . "-release-tree");
|
|
:set SentRouterosUpdateNotification $LatestVersion;
|
|
}
|