mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
56 lines
1.9 KiB
Text
56 lines
1.9 KiB
Text
#!rsc
|
|
# RouterOS script: packages-update
|
|
# Copyright (c) 2019 Christian Hesse <mail@eworm.de>
|
|
#
|
|
# download packages and reboot for installation
|
|
|
|
:global DownloadPackage;
|
|
:global ScriptFromTerminal;
|
|
|
|
:local Update [ / system package update get ];
|
|
|
|
:if ([ :typeof ($Update->"latest-version") ] = "nothing") do={
|
|
:log warning "Latest version is not known.";
|
|
:error "Latest version is not known.";
|
|
}
|
|
|
|
:if ($Update->"installed-version" = $Update->"latest-version") do={
|
|
:log info ("Version " . $Update->"latest-version" . " is already installed.");
|
|
:error "No updates available.";
|
|
}
|
|
|
|
:foreach Package in=[ / system package find where !bundle ] do={
|
|
:local PkgName [ / system package get $Package name ];
|
|
if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={
|
|
:log error ("Download for package " . $PkgName . " failed.");
|
|
:error "Error: See log for details.";
|
|
}
|
|
}
|
|
|
|
: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 ] = 121) do={
|
|
:log info ("Rebooting for downgrade.");
|
|
:delay 1s;
|
|
/ system package downgrade;
|
|
}
|
|
}
|
|
|
|
:put "Do you want to (s)chedule reboot instead of (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;");
|
|
:log info ("Scheduled reboot for update between 03:00 and 04:00.");
|
|
:error ("Scheduled reboot.");
|
|
}
|
|
}
|
|
|
|
:log info ("Rebooting for update.");
|
|
:delay 1s;
|
|
/ system reboot;
|