diff --git a/simple-routeros-update.rsc b/simple-routeros-update.rsc new file mode 100644 index 00000000..0143f996 --- /dev/null +++ b/simple-routeros-update.rsc @@ -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 +# 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"}; + diff --git a/simple-routeros-update.sh b/simple-routeros-update.sh new file mode 100755 index 00000000..293f99ae --- /dev/null +++ b/simple-routeros-update.sh @@ -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: 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: 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::' +# example: ssh -l admin 'fe80::ba69:f4ff:fe77:beef%enx00b56d00e148' +# +# Temporal connection via Winbox: +# [fe80:....%n] +# example: [fe80::ba69:f4ff:fe77:beef%9] +#