introduce global-config-overlay

This commit is contained in:
Christian Hesse 2019-09-03 20:59:00 +02:00
parent 2258087aab
commit 1cee36a911
7 changed files with 41 additions and 17 deletions

View file

@ -26,7 +26,7 @@ Initial setup
If you know how things work just copy and paste the
[initial commands](initial-commands). Remember to edit and rerun
`global-config`!
`global-config-overlay`!
First time useres should take the long way below.
### Live presentation
@ -85,18 +85,18 @@ crap and a good example how to *not* do it.
Now let's download the main scripts and add them in configuration on the fly.
[admin@MikroTik] > :foreach Script in={ "global-config"; "global-functions"; "script-updates" } do={ / system script add name=$Script source=([ / tool fetch check-certificate=yes-without-crl ("https://git.eworm.de/cgit/routeros-scripts/plain/" . $Script) output=user as-value]->"data"); }
[admin@MikroTik] > :foreach Script in={ "global-config"; "global-config-overlay"; "global-functions"; "script-updates" } do={ / system script add name=$Script source=([ / tool fetch check-certificate=yes-without-crl ("https://git.eworm.de/cgit/routeros-scripts/plain/" . $Script) output=user as-value]->"data"); }
The configuration needs to be tweaked for your needs. Make sure not to send
your mails to `mail@example.com`!
your mails to `mail@example.com`! Edit `global-config-overlay`, copy
configuration from `global-config`.
[admin@MikroTik] > / system script edit global-config source
[admin@MikroTik] > / system script edit global-config-overlay source
And finally load configuration and functions and add the scheduler.
[admin@MikroTik] > / system script run global-config
[admin@MikroTik] > / system script run global-functions
[admin@MikroTik] > / system scheduler add name="global-scripts" start-time=startup on-event="/ system script { run global-config; run global-functions; }"
[admin@MikroTik] > / system script { run global-config; run global-config-overlay; run global-functions; }
[admin@MikroTik] > / system scheduler add name="global-scripts" start-time=startup on-event="/ system script { run global-config; run global-config-overlay; run global-functions; }"
Updating scripts
----------------

View file

@ -6,7 +6,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
:global GlobalConfigVersion 8;
:global GlobalConfigVersion 9;
# This is used for DNS and backup file.
:global Domain "example.com";

18
global-config-overlay Normal file
View file

@ -0,0 +1,18 @@
#!rsc
# RouterOS script: global-config-overlay
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
#
# global configuration, custom overlay
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
:global GlobalConfigVersion 9;
# The global-config script is updated by script-updates,
# global-config-overlay becomes an overlay for your changes.
:global ScriptUpdatesIgnore {
"global-config-overlay"
}
# Copy configuration from global-config here and modify it.

View file

@ -11,4 +11,5 @@
6="introduced script 'upload-backup' with new configuration parameters";
7="introduced script 'check-health' with new configuration parameters";
8="added donation hint and option to silence it";
9="introduced configuration overlay 'global-config-overlay'";
};

View file

@ -6,7 +6,7 @@
# global functions
# expected configuration version
:global ExpectedConfigVersion 8;
:global ExpectedConfigVersion 9;
# global variables not to be changed by user
:global SentConfigChangesNotification "-";

View file

@ -15,12 +15,9 @@
:error "Anything is wrong with your certificates!";
}
/ file remove "letsencrypt.pem";
:foreach Script in={ "global-config"; "global-functions"; "script-updates" } do={
:foreach Script in={ "global-config"; "global-config-overlay"; "global-functions"; "script-updates" } do={
/ system script add name=$Script source=([ / tool fetch check-certificate=yes-without-crl ("https://git.eworm.de/cgit/routeros-scripts/plain/" . $Script) output=user as-value]->"data");
}
/ system script {
run global-config;
run global-functions;
}
/ system scheduler add name="global-scripts" start-time=startup on-event="/ system script { run global-config; run global-functions; }"
/ system script { run global-config; run global-config-overlay; run global-functions; }
/ system scheduler add name="global-scripts" start-time=startup on-event="/ system script { run global-config; run global-config-overlay; run global-functions; }"
}

View file

@ -63,6 +63,10 @@
:log info ("Updating script: " . $ScriptVal->"name");
/ system script set owner=($ScriptVal->"name") source=$SourceNew \
dont-require-permissions=$DontRequirePermissions $Script;
:if ($ScriptVal->"name" = "global-config" && \
[ / system script print count-only where name="global-config-overlay" ] > 0) do={
/ system script { run global-config; run global-config-overlay; }
}
:if ($ScriptVal->"name" = "global-functions") do={
/ system script run global-functions;
}
@ -82,10 +86,14 @@
$GlobalConfigVersion < $ExpectedConfigVersion) do={
:global GlobalConfigChanges;
:local ChangeLogCode;
:local ConfigScript "global-config";
:if ([ /system script print count-only where name="global-config-overlay" ] > 0) do={
:set ConfigScript "global-config-overlay";
}
:local NotificationMessage ("Current configuration on " . $Identity . \
" is out of date. Please update global-config, then increase " . \
" is out of date. Please update " . $ConfigScript . ", then increase " . \
"variable GlobalConfigVersion (currently " . $GlobalConfigVersion . \
") to " . $ExpectedConfigVersion . " and re-run global-config.");
") to " . $ExpectedConfigVersion . " and re-run " . $ConfigScript . ".");
:log debug ("Fetching changelog.");
:do {