packages-update: do not install downgrade without confirmation

This commit is contained in:
Christian Hesse 2020-07-07 09:28:16 +02:00
parent c5767c8d23
commit b31d1a0f01

View file

@ -10,6 +10,7 @@
:global LogPrintExit;
:global ScriptFromTerminal;
:global ScriptLock;
:global VersionToNum;
$ScriptLock "packages-update";
@ -23,6 +24,23 @@ $ScriptLock "packages-update";
$LogPrintExit info ("Version " . $Update->"latest-version" . " is already installed.") true;
}
:local NumInstalled [ $VersionToNum ($Update->"installed-version") ];
:local NumLatest [ $VersionToNum ($Update->"latest-version") ];
:local DoDowngrade false;
:if ($NumInstalled > $NumLatest) do={
:if ([ $ScriptFromTerminal "packages-update" ] = true) do={
:put "Latest version is older than installed one. Want to downgrade? [y/N]";
:if (([ :terminal inkey timeout=60 ] % 32) = 25) do={
:set DoDowngrade true;
} else={
:put "Canceled...";
}
} else={
$LogPrintExit warning ("Not installing downgrade automatically.") 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={
@ -34,16 +52,13 @@ $ScriptLock "packages-update";
/ 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;
}
}
:if ($DoDowngrade = true) do={
$LogPrintExit info ("Rebooting for downgrade.") false;
:delay 1s;
/ system package downgrade;
}
:if ([ $ScriptFromTerminal "packages-update" ] = true) do={
: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 \