mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
Merge branch 'fetch-as-value'
This commit is contained in:
commit
8f4986af0b
4 changed files with 49 additions and 33 deletions
29
README.md
29
README.md
|
@ -8,6 +8,17 @@ to manage RouterOS devices or extend their functionality.
|
|||
|
||||
*Use at your own risk!*
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Latest version of the scripts require at least **RouterOS 6.43** to function
|
||||
properly. The changelog lists the corresponding change as follows:
|
||||
|
||||
> *) fetch - added "as-value" output format;
|
||||
|
||||
See branch `pre-6-43` if you want to use the scripts on devices with older
|
||||
RouterOS version.
|
||||
|
||||
Initial setup
|
||||
-------------
|
||||
|
||||
|
@ -51,22 +62,8 @@ Then we import the certificates.
|
|||
|
||||
Now let's download the main scripts, add them in configuration and remove the files.
|
||||
|
||||
[admin@MikroTik] > / tool fetch check-certificate=yes-without-crl dst-path="script-updates/global-config" "https://git.eworm.de/cgit.cgi/routeros-scripts/plain/global-config"
|
||||
status: finished
|
||||
downloaded: 1KiBC-z pause]
|
||||
total: 1KiB
|
||||
duration: 0s
|
||||
|
||||
[admin@MikroTik] > / tool fetch check-certificate=yes-without-crl dst-path="script-updates/script-updates" "https://git.eworm.de/cgit.cgi/routeros-scripts/plain/script-updates"
|
||||
status: finished
|
||||
downloaded: 1KiBC-z pause]
|
||||
total: 1KiB
|
||||
duration: 1s
|
||||
|
||||
[admin@MikroTik] > / system script add name=global-config source=[ / file get script-updates/global-config contents ]
|
||||
[admin@MikroTik] > / file remove script-updates/global-config
|
||||
[admin@MikroTik] > / system script add name=script-updates source=[ / file get script-updates/script-updates contents ]
|
||||
[admin@MikroTik] > / file remove script-updates/script-updates
|
||||
[admin@MikroTik] > / system script add name=global-config source=([ / tool fetch check-certificate=yes-without-crl "https://git.eworm.de/cgit.cgi/routeros-scripts/plain/global-config" output=user as-value]->"data")
|
||||
[admin@MikroTik] > / system script add name=script-updates source=([ / tool fetch check-certificate=yes-without-crl "https://git.eworm.de/cgit.cgi/routeros-scripts/plain/script-updates" 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`!
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
:global "identity";
|
||||
:global "email-general-to";
|
||||
:global "email-general-cc";
|
||||
:global "safe-update-url";
|
||||
:global "sent-routeros-update-notification";
|
||||
|
||||
:if ([ :len [ / system package find where name="wireless" disabled=no ] ] > 0) do={
|
||||
|
@ -20,15 +21,25 @@
|
|||
:local installedversion [ / system package update get installed-version ];
|
||||
:local latestversion [ / system package update get latest-version ];
|
||||
|
||||
:if ($"sent-routeros-update-notification" = $latestversion) do={
|
||||
:error ("Already sent the RouterOS update notification for version" . $latestversion . ".");
|
||||
}
|
||||
|
||||
:if ($installedversion != $latestversion) do={
|
||||
:local channel [ / system package update get channel ];
|
||||
:local model [ / system routerboard get model ];
|
||||
:local serialnumber [ / system routerboard get serial-number ];
|
||||
|
||||
:if ([ :len $"safe-update-url" ] > 0) do={
|
||||
:local result [ / tool fetch check-certificate=yes-without-crl \
|
||||
($"safe-update-url" . $channel) output=user as-value ];
|
||||
:if ($result->"status" = "finished" && $result->"data" = $latestversion) do={
|
||||
:log info ("Version " . $latestversion . " is assumed safe, updating...");
|
||||
/ system package update install;
|
||||
:error "Waiting for system to reboot.";
|
||||
}
|
||||
}
|
||||
|
||||
:if ($"sent-routeros-update-notification" = $latestversion) do={
|
||||
:error ("Already sent the RouterOS update notification for version" . $latestversion . ".");
|
||||
}
|
||||
|
||||
/ tool e-mail send to=$"email-general-to" cc=$"email-general-cc" \
|
||||
subject=("[" . $identity . "] RouterOS update notification") \
|
||||
body=("There is a RouterOS update available\n\n" . \
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
:global "backup-send-export" true;
|
||||
:global "backup-password" "v3ry-s3cr3t";
|
||||
|
||||
# Specify an address to enable auto update to version assumed safe.
|
||||
# The configured channel (bugfix, current, release-candidate) is appended.
|
||||
:global "safe-update-url" "";
|
||||
#:global "safe-update-url" "https://example.com/ros/safe-update/";
|
||||
|
||||
# This is used to update AAAA records and firewall address-list.
|
||||
:global "ipv6-interface" "br-local";
|
||||
:global "ipv6-pool" "telekom";
|
||||
|
|
|
@ -13,35 +13,38 @@
|
|||
:local ignore 0;
|
||||
:local scriptname [ / system script get $script name ];
|
||||
:local scriptfile [ / file find where name=("script-updates/" . $scriptname) ];
|
||||
:local sourcenew;
|
||||
:if ([ :len $scriptfile ] > 0) do={
|
||||
:set sourcenew [ / file get $scriptfile content ];
|
||||
/ file remove $scriptfile;
|
||||
}
|
||||
|
||||
:if ([ :len $scriptfile ] = 0 && $"script-updates-fetch" = true) do={
|
||||
:if ([ :len $sourcenew ] = 0 && $"script-updates-fetch" = true) do={
|
||||
:foreach "ignore-loop" in=$"script-updates-ignore" do={
|
||||
:if ($"ignore-loop" = $scriptname) do={ :set ignore 1; }
|
||||
}
|
||||
|
||||
:if ($ignore = 0) do={
|
||||
:log debug ("Fetching script from url: " . $scriptname);
|
||||
:do {
|
||||
/ tool fetch check-certificate=yes-without-crl \
|
||||
dst-path=("script-updates/" . $scriptname) \
|
||||
($"script-updates-baseurl" . $scriptname . $"script-updates-urlsuffix");
|
||||
:set scriptfile [ / file find where name=("script-updates/" . $scriptname) ];
|
||||
} on-error={
|
||||
:local result [ / tool fetch check-certificate=yes-without-crl \
|
||||
($"script-updates-baseurl" . $scriptname . $"script-updates-urlsuffix") \
|
||||
output=user as-value ];
|
||||
:if ($result->"status" = "finished") do={
|
||||
:set sourcenew ($result->"data");
|
||||
} else={
|
||||
:log debug ("Failed fetching " . $scriptname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:if ([ :len $scriptfile ] > 0) do={
|
||||
:local filecontent [ / file get $scriptfile content ];
|
||||
:local scriptsource [ / system script get $script source ];
|
||||
:if ($filecontent = $scriptsource) do={
|
||||
:if ([ :len $sourcenew ] > 0) do={
|
||||
:local sourcecurrent [ / system script get $script source ];
|
||||
:if ($sourcenew = $sourcecurrent) do={
|
||||
:log debug ("Script " . $scriptname . " did not change");
|
||||
} else={
|
||||
:log info ("Updating script: " . $scriptname);
|
||||
/ system script set owner=$scriptname source=$filecontent $script;
|
||||
/ system script set owner=$scriptname source=$sourcenew $script;
|
||||
}
|
||||
/ file remove $scriptfile;
|
||||
} else={
|
||||
:log debug ("No update for script " . $scriptname);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue