global-functions: $ScriptInstallUpdate: run migration unconditionally

We want the migration to run even if the notification is disabled.
This commit is contained in:
Christian Hesse 2021-03-04 12:06:47 +01:00
parent 9ab20bb927
commit d1741c99fe

View file

@ -666,6 +666,7 @@
} }
} }
:local ExpectedConfigVersionBefore $ExpectedConfigVersion;
:local ScriptInstallUpdateBefore [ :tostr $ScriptInstallUpdate ]; :local ScriptInstallUpdateBefore [ :tostr $ScriptInstallUpdate ];
:foreach Script in=[ / system script find where source~"^#!rsc( by RouterOS)\?\n" ] do={ :foreach Script in=[ / system script find where source~"^#!rsc( by RouterOS)\?\n" ] do={
@ -748,18 +749,12 @@
} }
} }
:if ($SentConfigChangesNotification!=$ExpectedConfigVersion && \ :if ($ExpectedConfigVersionBefore != $ExpectedConfigVersion) do={
$GlobalConfigVersion < $ExpectedConfigVersion) do={
:global GlobalConfigChanges; :global GlobalConfigChanges;
:global GlobalConfigMigration; :global GlobalConfigMigration;
:local ChangeLogCode; :local ChangeLogCode;
:local NotificationMessage ("Current configuration on " . $Identity . \
" is out of date. Please update global-config-overlay, then increase " . \
"\$GlobalConfigVersion (currently " . $GlobalConfigVersion . \
") to " . $ExpectedConfigVersion . " and re-run global-config-overlay.");
$LogPrintExit2 info $0 ($NotificationMessage) false;
$LogPrintExit2 debug $0 ("Fetching changelog.") false; $LogPrintExit2 debug $0 ("Fetching news, changes and migration.") false;
:do { :do {
:local Result [ / tool fetch check-certificate=yes-without-crl \ :local Result [ / tool fetch check-certificate=yes-without-crl \
($ScriptUpdatesBaseUrl . "global-config.changes" . $ScriptUpdatesUrlSuffix) \ ($ScriptUpdatesBaseUrl . "global-config.changes" . $ScriptUpdatesUrlSuffix) \
@ -768,37 +763,49 @@
:set ChangeLogCode ($Result->"data"); :set ChangeLogCode ($Result->"data");
} }
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed fetching changes!") false; $LogPrintExit2 warning $0 ("Failed fetching news, changes and migration!") false;
:set NotificationMessage ($NotificationMessage . \
"\n\nChanges are not available.");
} }
:if ([ :len $ChangeLogCode ] > 0) do={ :if ([ :len $ChangeLogCode ] > 0) do={
:if ([ $ValidateSyntax $ChangeLogCode ] = true) do={ :if ([ $ValidateSyntax $ChangeLogCode ] = true) do={
:set NotificationMessage ($NotificationMessage . "\n\nChanges:");
[ :parse $ChangeLogCode ]; [ :parse $ChangeLogCode ];
:for I from=($GlobalConfigVersion + 1) to=$ExpectedConfigVersion do={ } else={
$LogPrintExit2 warning $0 ("The changelog failed syntax validation!") false;
}
}
:if ([ :len $GlobalConfigMigration ] > 0) do={
:for I from=($ExpectedConfigVersionBefore + 1) to=$ExpectedConfigVersion do={
:local Migration ($GlobalConfigMigration->[ :tostr $I ]); :local Migration ($GlobalConfigMigration->[ :tostr $I ]);
:if ([ :typeof $Migration ] = "str") do={ :if ([ :typeof $Migration ] = "str") do={
:if ([ $ValidateSyntax $Migration ] = true) do={ :if ([ $ValidateSyntax $Migration ] = true) do={
$LogPrintExit2 info $0 ("Applying migration: " . $Migration) false; $LogPrintExit2 info $0 ("Applying migration for change " . $I . ": " . $Migration) false;
[ :parse $Migration ]; [ :parse $Migration ];
} else={ } else={
$LogPrintExit2 warning $0 ("Migration code for change " . $I . " failed syntax validation!") false; $LogPrintExit2 warning $0 ("Migration code for change " . $I . " failed syntax validation!") false;
} }
} }
:set NotificationMessage ($NotificationMessage . \
"\n " . [ $IfThenElse ($NotificationsWithSymbols = true) ("\E2\97\8F") "*" ] . " " . \
$GlobalConfigChanges->[ :tostr $I ]);
$LogPrintExit2 info $0 ("Change: " . $GlobalConfigChanges->[ :tostr $I ]) false;
} }
:set GlobalConfigChanges; }
:set GlobalConfigMigration;
:if ($SentConfigChangesNotification != $ExpectedConfigVersion && \
$GlobalConfigVersion < $ExpectedConfigVersion) do={
:local NotificationMessage ("Current configuration on " . $Identity . \
" is out of date. Please update global-config-overlay, then increase " . \
"\$GlobalConfigVersion (currently " . $GlobalConfigVersion . \
") to " . $ExpectedConfigVersion . " and re-run global-config-overlay.");
$LogPrintExit2 info $0 ($NotificationMessage) false;
:if ([ :len $GlobalConfigChanges ] > 0) do={
:set NotificationMessage ($NotificationMessage . "\n\nChanges:");
:for I from=($GlobalConfigVersion + 1) to=$ExpectedConfigVersion do={
:local Change ($GlobalConfigChanges->[ :tostr $I ]);
:set NotificationMessage ($NotificationMessage . "\n " . \
[ $IfThenElse ($NotificationsWithSymbols = true) ("\E2\97\8F") "*" ] . " " . $Change);
$LogPrintExit2 info $0 ("Change " . $I . ": " . $Change) false;
}
} else={ } else={
$LogPrintExit2 warning $0 ("The changelog failed syntax validation!") false; :set NotificationMessage ($NotificationMessage . "\n\nNews and changes are not available.");
:set NotificationMessage ($NotificationMessage . \
"\n\nChanges are not available.");
}
} }
:local Link; :local Link;
@ -816,6 +823,10 @@
:set SentConfigChangesNotification $ExpectedConfigVersion; :set SentConfigChangesNotification $ExpectedConfigVersion;
} }
:set GlobalConfigChanges;
:set GlobalConfigMigration;
}
:if ($ScriptInstallUpdateBefore != [ :tostr $ScriptInstallUpdate ]) do={ :if ($ScriptInstallUpdateBefore != [ :tostr $ScriptInstallUpdate ]) do={
$LogPrintExit2 info $0 ("This function changed, you may want to re-run.") false; $LogPrintExit2 info $0 ("This function changed, you may want to re-run.") false;
} }