packages-update: RouterOS v7 path syntax

This commit is contained in:
Christian Hesse 2022-05-10 15:13:05 +02:00
parent 008046d569
commit ba0bb3d2d4

View file

@ -18,7 +18,7 @@
$ScriptLock $0; $ScriptLock $0;
:local Update [ / system package update get ]; :local Update [ /system/package/update/get ];
:if ([ :typeof ($Update->"latest-version") ] = "nothing") do={ :if ([ :typeof ($Update->"latest-version") ] = "nothing") do={
$LogPrintExit2 warning $0 ("Latest version is not known.") true; $LogPrintExit2 warning $0 ("Latest version is not known.") true;
@ -35,7 +35,7 @@ $ScriptLock $0;
:if ($NumInstalled > $NumLatest) do={ :if ($NumInstalled > $NumLatest) do={
:if ([ $ScriptFromTerminal $0 ] = true) do={ :if ([ $ScriptFromTerminal $0 ] = true) do={
:put "Latest version is older than installed one. Want to downgrade? [y/N]"; :put "Latest version is older than installed one. Want to downgrade? [y/N]";
:if (([ / terminal inkey timeout=60 ] % 32) = 25) do={ :if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={
:set DoDowngrade true; :set DoDowngrade true;
} else={ } else={
:put "Canceled..."; :put "Canceled...";
@ -45,23 +45,23 @@ $ScriptLock $0;
} }
} }
:foreach Package in=[ / system package find where !bundle ] do={ :foreach Package in=[ /system/package/find where !bundle ] do={
:local PkgName [ / system package get $Package name ]; :local PkgName [ /system/package/get $Package name ];
:if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={ :if ([ $DownloadPackage $PkgName ($Update->"latest-version") ] = false) do={
$LogPrintExit2 error $0 ("Download for package " . $PkgName . " failed, update aborted.") true; $LogPrintExit2 error $0 ("Download for package " . $PkgName . " failed, update aborted.") true;
} }
} }
:foreach Script in=[ / system script find where source~"\n# provides: backup-script\n" ] do={ :foreach Script in=[ /system/script/find where source~"\n# provides: backup-script\n" ] do={
:local ScriptName [ / system script get $Script name ]; :local ScriptName [ /system/script/get $Script name ];
:do { :do {
$LogPrintExit2 info $0 ("Running backup script " . $ScriptName . " before update.") false; $LogPrintExit2 info $0 ("Running backup script " . $ScriptName . " before update.") false;
/ system script run $Script; /system/script/run $Script;
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Running backup script " . $ScriptName . " before update failed!") false; $LogPrintExit2 warning $0 ("Running backup script " . $ScriptName . " before update failed!") false;
:if ([ $ScriptFromTerminal $0 ] = true) do={ :if ([ $ScriptFromTerminal $0 ] = true) do={
:put "Do you want to continue anyway? [y/N]"; :put "Do you want to continue anyway? [y/N]";
:if (([ / terminal inkey timeout=60 ] % 32) = 25) do={ :if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={
$LogPrintExit2 info $0 ("User requested to continue anyway.") false; $LogPrintExit2 info $0 ("User requested to continue anyway.") false;
} else={ } else={
$LogPrintExit2 info $0 ("Canceled update...") true; $LogPrintExit2 info $0 ("Canceled update...") true;
@ -75,19 +75,19 @@ $ScriptLock $0;
:if ($DoDowngrade = true) do={ :if ($DoDowngrade = true) do={
$LogPrintExit2 info $0 ("Rebooting for downgrade.") false; $LogPrintExit2 info $0 ("Rebooting for downgrade.") false;
:delay 1s; :delay 1s;
/ system package downgrade; /system/package/downgrade;
} }
:if ([ $ScriptFromTerminal $0 ] = true) do={ :if ([ $ScriptFromTerminal $0 ] = true) do={
:put "Do you want to (s)chedule reboot or (r)eboot now? [s/R]"; :put "Do you want to (s)chedule reboot or (r)eboot now? [s/R]";
:if (([ / terminal inkey timeout=60 ] % 32) = 19) do={ :if (([ /terminal/inkey timeout=60 ] % 32) = 19) do={
/ system scheduler add name="reboot-for-update" start-time=03:00:00 interval=1d \ /system/scheduler/add name="reboot-for-update" start-time=03:00:00 interval=1d \
on-event=(":global RandomDelay; \$RandomDelay 3600; " . \ on-event=(":global RandomDelay; \$RandomDelay 3600; " . \
"/ system scheduler remove reboot-for-update; / system reboot;"); "/system/scheduler/remove reboot-for-update; /system/reboot;");
$LogPrintExit2 info $0 ("Scheduled reboot for update between 03:00 and 04:00.") true; $LogPrintExit2 info $0 ("Scheduled reboot for update between 03:00 and 04:00.") true;
} }
} }
$LogPrintExit2 info $0 ("Rebooting for update.") false; $LogPrintExit2 info $0 ("Rebooting for update.") false;
:delay 1s; :delay 1s;
/ system reboot; /system/reboot;