diff options
author | Christian Hesse <mail@eworm.de> | 2023-09-13 01:01:34 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2023-09-13 01:14:27 +0200 |
commit | c3f9ad1df7422fb2c508ea4960bd95b4a2ef25b2 (patch) | |
tree | b76551814d6674dae86c9a3de9389cf78e3366a2 | |
parent | 50429a0ad8ce02f26f40a69d027ea709480aeb36 (diff) |
packages-update: implement backup script order
-rw-r--r-- | backup-cloud.rsc | 2 | ||||
-rw-r--r-- | backup-email.rsc | 2 | ||||
-rw-r--r-- | backup-partition.rsc | 2 | ||||
-rw-r--r-- | backup-upload.rsc | 2 | ||||
-rw-r--r-- | packages-update.rsc | 18 |
5 files changed, 18 insertions, 8 deletions
diff --git a/backup-cloud.rsc b/backup-cloud.rsc index 859892b..934edb9 100644 --- a/backup-cloud.rsc +++ b/backup-cloud.rsc @@ -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 diff --git a/backup-email.rsc b/backup-email.rsc index e4cd504..95e9015 100644 --- a/backup-email.rsc +++ b/backup-email.rsc @@ -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 diff --git a/backup-partition.rsc b/backup-partition.rsc index 364101c..b03ad7e 100644 --- a/backup-partition.rsc +++ b/backup-partition.rsc @@ -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 diff --git a/backup-upload.rsc b/backup-upload.rsc index 7d4b1d1..4c8af4a 100644 --- a/backup-upload.rsc +++ b/backup-upload.rsc @@ -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 diff --git a/packages-update.rsc b/packages-update.rsc index 74b1822..ebcbaae 100644 --- a/packages-update.rsc +++ b/packages-update.rsc @@ -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={ |