mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-04-16 10:09:37 +00:00
Merge f26cb2a105 into 492edcd23f
This commit is contained in:
commit
b606eca3f0
2 changed files with 132 additions and 0 deletions
58
simple-routeros-update.rsc
Normal file
58
simple-routeros-update.rsc
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#!rsc by Guillen
|
||||
#
|
||||
# Script: simple-routeros-update.rsc
|
||||
#
|
||||
# Copied and adaptated from RouterOS script: packages-update
|
||||
# Copyright (c) 2019-2025 Christian Hesse <mail@eworm.de>
|
||||
# https://rsc.eworm.de/COPYING.md
|
||||
#
|
||||
# download packages and reboot for installation
|
||||
# https://rsc.eworm.de/doc/packages-update.md
|
||||
#
|
||||
# RouterOS upgrade for a new or repurposed Mikrotik.
|
||||
# Works even with very old RouterOS versions
|
||||
# WARNING: reboots router after each upgrade
|
||||
#
|
||||
{:put "START script simple-routeros-update"};
|
||||
|
||||
{
|
||||
:local ScriptName "simple-routeros-update";
|
||||
:local LogPrint;
|
||||
|
||||
# Simplified LogPrint
|
||||
:set LogPrint do={
|
||||
:local Name [ :tostr $1 ];
|
||||
:local Message [ :tostr $2 ];
|
||||
|
||||
:log info ( $Name . ": " . $Message);
|
||||
:put ( $Name . ": " . $Message);
|
||||
}
|
||||
|
||||
#
|
||||
# Main block:
|
||||
#
|
||||
|
||||
$LogPrint $ScriptName "Checking for updates...";
|
||||
/system/package/update/check-for-updates without-paging;
|
||||
$LogPrint $ScriptName "Installing updates (if any) ...";
|
||||
/system/package/update/install without-paging;
|
||||
|
||||
$LogPrint $ScriptName "Checking firmware upgrade ...";
|
||||
|
||||
:local RouterBoard [ /system/routerboard/get ];
|
||||
:if ($RouterBoard->"current-firmware" = $RouterBoard->"upgrade-firmware") do={
|
||||
$LogPrint $ScriptName ("Firmware already updated:" . $RouterBoard->"current-firmware" . ".");
|
||||
} else={
|
||||
:if ([ /system/routerboard/settings/get auto-upgrade ] = false) do={
|
||||
$LogPrint $ScriptName ("Firmware " . $RouterBoard->"upgrade-firmware" . " available, upgrading.");
|
||||
:delay 5s;
|
||||
/system/routerboard/upgrade;
|
||||
$LogPrint $ScriptName ("Rebooting...");
|
||||
:delay 5s;
|
||||
/system/reboot;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
{:put "END script simple-routeros-update"};
|
||||
|
||||
74
simple-routeros-update.sh
Executable file
74
simple-routeros-update.sh
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# File: simple-routeros-update.sh
|
||||
# Description: Upgrade to the last routeros stable version
|
||||
# Author: Miquel Bonastre
|
||||
# Date: 2025-03-11
|
||||
#
|
||||
# Inputs:
|
||||
# $1 - ssh user to use to connect to Mikrotik (usualy "admin")
|
||||
# $2 - Mikrotik address
|
||||
#
|
||||
# The address can be:
|
||||
# - Previously configured IP address
|
||||
# - Default address: 192.168.88.1
|
||||
# - Local link IPv6 address
|
||||
#
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
echo Missing parameters
|
||||
echo $0 user addr
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SSH="ssh -nq"
|
||||
SCP="scp -q"
|
||||
|
||||
if ! $SSH -l "$1" "$2" ":put" \"Hello World\" \; ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Copy simple-routeros-update.rsc via scp:"
|
||||
$SCP simple-routeros-update.rsc "$1@[$2]":
|
||||
|
||||
echo "Exec simple-routeros-update via ssh:"
|
||||
$SSH -l "$1" "$2" "/import simple-routeros-update.rsc;"
|
||||
|
||||
echo "Force exit if router has restarted (execute again until last version installed)"
|
||||
$SSH -l "$1" "$2" "/system/clock/print" || exit 1
|
||||
|
||||
echo "If you see the output of /system/clock/print means there are no more upgrades"
|
||||
|
||||
echo "End of simple-routeros-update"
|
||||
|
||||
|
||||
# How to find router's local link IPv6 address:
|
||||
# ping -6 fe80::%n
|
||||
#
|
||||
# Where n is the number of the interface where the router can be found as reported by "ip link":
|
||||
#
|
||||
# Example:
|
||||
# $ ip link
|
||||
# 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
|
||||
# link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
||||
# 3: enx207bd2dc0ebe: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
|
||||
# link/ether 20:7b:d2:dc:0e:be brd ff:ff:ff:ff:ff:ff
|
||||
#
|
||||
# ping -6 'fe80::%9' -c 4
|
||||
# PING fe80::%9(fe80::%enx00b56d00e148) 56 data bytes
|
||||
# 64 bytes from fe80::ba69:f4ff:fe77:beef%enx00b56d00e148: icmp_seq=1 ttl=64 time=0.405 ms
|
||||
# 64 bytes from fe80::ba69:f4ff:fe77:beef%enx00b56d00e148: icmp_seq=2 ttl=64 time=0.479 ms
|
||||
# 64 bytes from fe80::ba69:f4ff:fe77:beef%enx00b56d00e148: icmp_seq=3 ttl=64 time=0.461 ms
|
||||
# 64 bytes from fe80::ba69:f4ff:fe77:beef%enx00b56d00e148: icmp_seq=4 ttl=64 time=0.374 ms
|
||||
# --- fe80::%9 ping statistics ---
|
||||
# 4 packets transmitted, 4 received, 0% packet loss, time 3053ms
|
||||
# rtt min/avg/max/mdev = 0.374/0.429/0.479/0.042 ms
|
||||
#
|
||||
# Temporal connection to Mikrotik via ssh:
|
||||
# ssh -l admin 'fe80::<found values>'
|
||||
# example: ssh -l admin 'fe80::ba69:f4ff:fe77:beef%enx00b56d00e148'
|
||||
#
|
||||
# Temporal connection via Winbox:
|
||||
# [fe80:....%n]
|
||||
# example: [fe80::ba69:f4ff:fe77:beef%9]
|
||||
#
|
||||
Loading…
Add table
Add a link
Reference in a new issue