routeros-scripts/packages-update
Christian Hesse 71ad56aacc explicitly name the license
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
2020-06-19 22:17:42 +02:00

58 lines
2 KiB
Text

#!rsc
# RouterOS script: packages-update
# Copyright (c) 2019-2020 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# download packages and reboot for installation
# https://git.eworm.de/cgit/routeros-scripts/about/doc/packages-update.md
:global DownloadPackage;
:global LogPrintExit;
:global ScriptFromTerminal;
:global ScriptLock;
$ScriptLock "packages-update";
:local Update [ / system package update get ];
:if ([ :typeof ($Update->"latest-version") ] = "nothing") do={
$LogPrintExit warning "Latest version is not known." true;
}
:if ($Update->"installed-version" = $Update->"latest-version") do={
$LogPrintExit info ("Version " . $Update->"latest-version" . " is already installed.") true;
}
:foreach Package in=[ / system package find where !bundle ] do={
:local PkgName [ / system package get $Package name ];
if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={
$LogPrintExit error ("Download for package " . $PkgName . " failed.") true;
}
}
:foreach Script in=[ / system script find where name~"^(email|upload)-backup\$" ] do={
/ system script run $Script;
}
:if ([ $ScriptFromTerminal "packages-update" ] = true) do={
:if (!([ /system resource get version ] ~ ($Update->"channel"))) do={
:put "Update channel changed. Want to downgrade? [y/N]";
:if (([ :terminal inkey timeout=60 ] % 32) = 25) do={
$LogPrintExit info ("Rebooting for downgrade.") false;
:delay 1s;
/ system package downgrade;
}
}
:put "Do you want to (s)chedule reboot or (r)eboot now? [s/R]";
:if (([ :terminal inkey timeout=60 ] % 32) = 19) do={
/ system scheduler add name="reboot-for-update" start-time=03:00:00 interval=1d \
on-event=(":global RandomDelay; \$RandomDelay 3600; " . \
"/ system scheduler remove reboot-for-update; / system reboot;");
$LogPrintExit info ("Scheduled reboot for update between 03:00 and 04:00.") true;
}
}
$LogPrintExit info ("Rebooting for update.") false;
:delay 1s;
/ system reboot;