routeros-scripts/packages-update

57 lines
1.8 KiB
Text
Raw Normal View History

2019-02-19 15:41:27 +00:00
#!rsc
# RouterOS script: packages-update
2020-01-01 16:00:39 +00:00
# Copyright (c) 2019-2020 Christian Hesse <mail@eworm.de>
2019-02-19 15:41:27 +00:00
#
# download packages and reboot for installation
:global DownloadPackage;
2020-02-28 14:26:26 +00:00
:global LogPrintExit;
:global ScriptFromTerminal;
:global ScriptLock;
$ScriptLock "packages-update";
2019-02-19 15:41:27 +00:00
2019-07-24 08:13:39 +00:00
:local Update [ / system package update get ];
2019-02-19 15:41:27 +00:00
:if ([ :typeof ($Update->"latest-version") ] = "nothing") do={
$LogPrintExit warning "Latest version is not known." true;
}
2019-07-24 08:13:39 +00:00
:if ($Update->"installed-version" = $Update->"latest-version") do={
$LogPrintExit info ("Version " . $Update->"latest-version" . " is already installed.") true;
2019-02-19 15:41:27 +00:00
}
:foreach Package in=[ / system package find where !bundle ] do={
:local PkgName [ / system package get $Package name ];
2019-07-24 08:13:39 +00:00
if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={
$LogPrintExit error ("Download for package " . $PkgName . " failed.") true;
2019-02-19 15:41:27 +00:00
}
}
:foreach Script in=[ / system script find where name~"^(email|upload)-backup\$" ] do={
/ system script run $Script;
2019-02-19 15:41:27 +00:00
}
: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 ] = 121) do={
:log info ("Rebooting for downgrade.");
:delay 1s;
/ system package downgrade;
}
}
2019-12-20 13:38:42 +00:00
:put "Do you want to (s)chedule reboot or (r)eboot now? [s/R]";
:if ([ :terminal inkey timeout=60 ] = 115) 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;
}
}
2019-02-19 15:41:27 +00:00
:log info ("Rebooting for update.");
:delay 1s;
/ system reboot;