packages-update: implement backup script order

This commit is contained in:
Christian Hesse 2023-09-13 01:01:34 +02:00
parent 50429a0ad8
commit c3f9ad1df7
5 changed files with 18 additions and 8 deletions

View file

@ -3,7 +3,7 @@
# Copyright (c) 2013-2023 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# provides: backup-script
# provides: backup-script, order=40
#
# upload backup to MikroTik cloud
# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-cloud.md

View file

@ -3,7 +3,7 @@
# Copyright (c) 2013-2023 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# provides: backup-script
# provides: backup-script, order=20
#
# create and email backup and config file
# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-email.md

View file

@ -3,7 +3,7 @@
# Copyright (c) 2022-2023 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# provides: backup-script
# provides: backup-script, order=70
#
# save configuration to fallback partition
# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-partition.md

View file

@ -3,7 +3,7 @@
# Copyright (c) 2013-2023 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# provides: backup-script
# provides: backup-script, order=50
#
# create and upload backup and config file
# https://git.eworm.de/cgit/routeros-scripts/about/doc/backup-upload.md

View file

@ -11,7 +11,9 @@
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:global DownloadPackage;
:global Grep;
:global LogPrintExit2;
:global ParseKeyValueStore;
:global ScriptFromTerminal;
:global ScriptLock;
:global VersionToNum;
@ -52,13 +54,21 @@ $ScriptLock $0;
}
}
:foreach Script in=[ /system/script/find where source~"\n# provides: backup-script\n" ] do={
:local ScriptName [ /system/script/get $Script name ];
:local RunOrder ({});
:foreach Script in=[ /system/script/find where source~("\n# provides: backup-script, ") ] do={
:local ScriptVal [ /system/script/get $Script ];
:local Store [ $ParseKeyValueStore [ $Grep ($ScriptVal->"source") ("\23 provides: backup-script, ") ] ];
:set ($RunOrder->($Store->"order" . "-" . $ScriptVal->"name")) ($ScriptVal->"name");
}
:foreach Order,Script in=$RunOrder do={
:do {
$LogPrintExit2 info $0 ("Running backup script " . $ScriptName . " before update.") false;
$LogPrintExit2 info $0 ("Running backup script " . $Script . " (order " . $Order . ") before update.") false;
/system/script/run $Script;
} on-error={
$LogPrintExit2 warning $0 ("Running backup script " . $ScriptName . " before update failed!") false;
$LogPrintExit2 warning $0 ("Running backup script " . $Script . " before update failed!") false;
:if ([ $ScriptFromTerminal $0 ] = true) do={
:put "Do you want to continue anyway? [y/N]";
:if (([ /terminal/inkey timeout=60 ] % 32) = 25) do={