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,52 +763,68 @@
: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={
:local Migration ($GlobalConfigMigration->[ :tostr $I ]);
:if ([ :typeof $Migration ] = "str") do={
:if ([ $ValidateSyntax $Migration ] = true) do={
$LogPrintExit2 info $0 ("Applying migration: " . $Migration) false;
[ :parse $Migration ];
} else={
$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;
} else={ } else={
$LogPrintExit2 warning $0 ("The changelog failed syntax validation!") false; $LogPrintExit2 warning $0 ("The changelog failed syntax validation!") false;
:set NotificationMessage ($NotificationMessage . \
"\n\nChanges are not available.");
} }
} }
:local Link; :if ([ :len $GlobalConfigMigration ] > 0) do={
:if ($IDonate != true) do={ :for I from=($ExpectedConfigVersionBefore + 1) to=$ExpectedConfigVersion do={
:set NotificationMessage ($NotificationMessage . \ :local Migration ($GlobalConfigMigration->[ :tostr $I ]);
"\n\n==== donation hint ====\n" . \ :if ([ :typeof $Migration ] = "str") do={
"This project is developed in private spare time and usage is " . \ :if ([ $ValidateSyntax $Migration ] = true) do={
"free of charge for you. If you like the scripts and think this is " . \ $LogPrintExit2 info $0 ("Applying migration for change " . $I . ": " . $Migration) false;
"of value for you or your business please consider a donation."); [ :parse $Migration ];
:set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate"; } else={
$LogPrintExit2 warning $0 ("Migration code for change " . $I . " failed syntax validation!") false;
}
}
}
} }
$SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \ :if ($SentConfigChangesNotification != $ExpectedConfigVersion && \
$NotificationMessage $Link; $GlobalConfigVersion < $ExpectedConfigVersion) do={
:set SentConfigChangesNotification $ExpectedConfigVersion; :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={
:set NotificationMessage ($NotificationMessage . "\n\nNews and changes are not available.");
}
:local Link;
:if ($IDonate != true) do={
:set NotificationMessage ($NotificationMessage . \
"\n\n==== donation hint ====\n" . \
"This project is developed in private spare time and usage is " . \
"free of charge for you. If you like the scripts and think this is " . \
"of value for you or your business please consider a donation.");
:set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate";
}
$SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \
$NotificationMessage $Link;
:set SentConfigChangesNotification $ExpectedConfigVersion;
}
:set GlobalConfigChanges;
:set GlobalConfigMigration;
} }
:if ($ScriptInstallUpdateBefore != [ :tostr $ScriptInstallUpdate ]) do={ :if ($ScriptInstallUpdateBefore != [ :tostr $ScriptInstallUpdate ]) do={