aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2022-02-02 21:10:10 +0100
committerGravatar Christian Hesse <mail@eworm.de>2022-02-10 09:07:32 +0100
commit3c358980cb416c61419a0aaa384ab1db1dab8d29 (patch)
treea894de1de2cf3687f1f873be94966e4941a778e9
parenta47f5723cc4cdd287d36aaffd7619c17494f9345 (diff)
introduce firmware-upgrade-rebootchange-77
-rw-r--r--README.md1
-rw-r--r--doc/check-routeros-update.md1
-rw-r--r--doc/firmware-upgrade-reboot.md36
-rw-r--r--doc/packages-update.md1
-rw-r--r--firmware-upgrade-reboot32
-rw-r--r--global-config2
-rw-r--r--global-config-overlay2
-rw-r--r--global-config.changes1
-rw-r--r--global-functions2
9 files changed, 75 insertions, 3 deletions
diff --git a/README.md b/README.md
index 02cb009..43b8c58 100644
--- a/README.md
+++ b/README.md
@@ -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)
diff --git a/doc/check-routeros-update.md b/doc/check-routeros-update.md
index 9385341..d55fa08 100644
--- a/doc/check-routeros-update.md
+++ b/doc/check-routeros-update.md
@@ -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)
---
diff --git a/doc/firmware-upgrade-reboot.md b/doc/firmware-upgrade-reboot.md
new file mode 100644
index 0000000..6afc40e
--- /dev/null
+++ b/doc/firmware-upgrade-reboot.md
@@ -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)
diff --git a/doc/packages-update.md b/doc/packages-update.md
index 309a394..a56f68e 100644
--- a/doc/packages-update.md
+++ b/doc/packages-update.md
@@ -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)
diff --git a/firmware-upgrade-reboot b/firmware-upgrade-reboot
new file mode 100644
index 0000000..b3cb621
--- /dev/null
+++ b/firmware-upgrade-reboot
@@ -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;
diff --git a/global-config b/global-config
index 37a60e8..50e7f54 100644
--- a/global-config
+++ b/global-config
@@ -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";
diff --git a/global-config-overlay b/global-config-overlay
index 8e1a664..d8c2e0a 100644
--- a/global-config-overlay
+++ b/global-config-overlay
@@ -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.
diff --git a/global-config.changes b/global-config.changes
index 271d232..727b259 100644
--- a/global-config.changes
+++ b/global-config.changes
@@ -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
diff --git a/global-functions b/global-functions
index 0bdbb48..4d1d1a1 100644
--- a/global-functions
+++ b/global-functions
@@ -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;