introduce firmware-upgrade-reboot

This commit is contained in:
Christian Hesse 2022-02-02 21:10:10 +01:00
parent a47f5723cc
commit 3c358980cb
9 changed files with 75 additions and 3 deletions

View file

@ -189,6 +189,7 @@ Available scripts
* [Use wireless network with daily psk](doc/daily-psk.md)
* [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md)
* [Create DNS records for DHCP leases](doc/dhcp-to-dns.md)
* [Automatically upgrade firmware and reboot](doc/firmware-upgrade-reboot.md)
* [Wait for global functions und modules](doc/global-wait.md)
* [Send GPS position to server](doc/gps-track.md)
* [Use WPA2 network with hotspot credentials](doc/hotspot-to-wpa.md)

View file

@ -61,6 +61,7 @@ Installing script [packages-update](packages-update.md) gives extra options.
See also
--------
* [Automatically upgrade firmware and reboot](firmware-upgrade-reboot.md)
* [Manage system update](packages-update.md)
---

View file

@ -0,0 +1,36 @@
Automatically upgrade firmware and reboot
=========================================
[◀ Go back to main README](../README.md)
🛈 This script can not be used on its own but requires the base installation.
See [main README](../README.md) for details.
Description
-----------
RouterOS and firmware are upgraded separately, activating the latter
requires an extra reboot. This script handles upgrade and reboot.
⚠️ **Warning**: This *should* be bullet proof, but I can not guarantee. In
worst case it has potential to cause a boot loop, so handle with care!
Requirements and installation
-----------------------------
Just install the script and create a scheduler:
$ScriptInstallUpdate firmware-upgrade-reboot;
/ system scheduler add name=firmware-upgrade-reboot on-event="/ system script run firmware-upgrade-reboot;" start-time=startup;
Enjoy firmware being up to date and in sync with RouterOS.
See also
--------
* [Notify on RouterOS update](check-routeros-update.md)
* [Manage system update](packages-update.md)
---
[◀ Go back to main README](../README.md)
[▲ Go back to top](#top)

View file

@ -44,6 +44,7 @@ See also
* [Upload backup to Mikrotik cloud](backup-cloud.md)
* [Send backup via e-mail](backup-email.md)
* [Upload backup to server](backup-upload.md)
* [Automatically upgrade firmware and reboot](firmware-upgrade-reboot.md)
---
[◀ Go back to main README](../README.md)

32
firmware-upgrade-reboot Normal file
View file

@ -0,0 +1,32 @@
#!rsc by RouterOS
# RouterOS script: firmware-upgrade-reboot
# Copyright (c) 2022 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# install firmware upgrade, and reboot
# https://git.eworm.de/cgit/routeros-scripts/about/doc/firmware-upgrade-reboot.md
:local 0 "firmware-upgrade-reboot";
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:global LogPrintExit2;
:local RouterBoard [ / system routerboard get ];
:if ($RouterBoard->"current-firmware" = $RouterBoard->"upgrade-firmware") do={
$LogPrintExit2 info $0 ("Firmware is already up to date.") true;
}
:if ([ / system routerboard settings get auto-upgrade ] = false) do={
$LogPrintExit2 info $0 ("Firmware version " . $RouterBoard->"upgrade-firmware" . \
" is available, upgrading.") false;
/ system routerboard upgrade;
}
:while ([ :len [ / log find where topics=({"system";"info";"critical"}) \
message="Firmware upgraded successfully, please reboot for changes to take effect!" ] ] = 0) do={
:delay 1s;
}
$LogPrintExit2 info $0 ("Firmware upgrade successful, rebooting.") false;
/ system reboot;

View file

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

View file

@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
# Comment or remove to disable news and change notifications.
:global GlobalConfigVersion 76;
:global GlobalConfigVersion 77;
# Copy configuration from global-config here and modify it.

View file

@ -85,6 +85,7 @@
("You may now drop '\$ScriptUpdatesUrlSuffix' from 'global-config-overlay'.") \
("Still running RouterOS v6, so last reminder to see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v6") ]);
76="Added an option to suppress notifications on host down with 'netwatch-notify'.";
77="Introduced new script 'firmware-upgrade-reboot'. Handle with care!";
};
# Migration steps to be applied on script updates

View file

@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version
:global ExpectedConfigVersion 76;
:global ExpectedConfigVersion 77;
# global variables not to be changed by user
:global GlobalFunctionsReady false;