[Mikrotik] Actualización automática de RouterBoard y RouterOS

Siempre es recomendable, tanto por usabilidad como por mejoras tener las versiones actualizadas tanto de RouterBoard como de RouterOS.
Estaba intentando realizarlo y me fallaba, intentando averiguar el fallo dí con él, así que para que hacerlo si hacía a la perfección lo que necesitaba. Comprueba y si encuentra la actualización la aplica. Si no pues no hace nada.

Es autor es Massimo Filippi.

Lógicamente este script sin una programación en el scheduler sirve de poco, y no es nada recomendable para Cores en Producción, pero si es muy recomendado (por lo menos yo así lo tengo puesto) que se ejecute de forma diaria en un horario en el que no te interfiera en el trabajo.

Básicamente lo que hace es actualizar el firmware del Mikrotik, o mejor dicho actualizar el RouterOS y Routerboard de nuestro Mikrotik de manera automática.

[Actualizado Febrero/2.018]: Debido a la nueva política de Mikrotik de crear un nuevo routerboard para cada versión de routeros, de manera que ambos sean parejos en versiones, recomiendo poner que se ejecute en dos ocasiones este script para el Mikrotik, ya que la primera vez nos actualizará el RouterOS y la segunda lo hará con el Routerboard.

[Actualizado Enero/2.019]: Debido al cambio de nombre de las  ramas de Mikrotik, ahora en vez de ver el channel current como hasta ahora, lo hace de la rama stable.

##
##   Automatically upgrade RouterOS and Firmware
##   https://github.com/massimo-filippi/mikrotik
##
##   script by Maxim Krusina, maxim@mfcc.cz
##   based on: http://wiki.mikrotik.com/wiki/Manual:Upgrading_RouterOS
##   created: 2014-12-05
##   updated: 2015-12-09
##   tested on: RouterOS 6.33.1 / multiple HW devices, won't work on 6.27 and older (different update process & value naming)
##


########## Set variables

## Notification e-mail
:local email "MICORREO@GMAIL.COM"


########## Do the stuff

## Check for update
/system package update
set channel=stable
check-for-updates

## Waint on slow connections
:delay 15s;

## Important note: "installed-version" was "current-version" on older Roter OSes
:if ([get installed-version] != [get latest-version]) do={ 

   ## New version of RouterOS available, let's upgrade
   /tool e-mail send to="$email" subject="Upgrading RouterOS on router $[/system identity get name]" body="Upgrading RouterOS on router $[/system identity get name] from $[/system package update get installed-version] to $[/system package update get latest-version] (channel:$[/system package update get channel])"
   :log info ("Upgrading RouterOS on router $[/system identity get name] from $[/system package update get installed-version] to $[/system package update get latest-version] (channel:$[/system package update get channel])")     

   ## Wait for mail to be send & upgrade
   :delay 15s;
   
   ## "install" command is reincarnation of the "upgrade" command - doing exactly the same but under a different name
   install

} else={

   ## RouterOS latest, let's check for updated firmware
    :log info ("No RouterOS upgrade found, checking for HW upgrade...")

   /system routerboard

   :if ( [get current-firmware] != [get upgrade-firmware]) do={ 

      ## New version of firmware available, let's upgrade
      /tool e-mail send to="$email" subject="Upgrading firmware on router $[/system identity get name]" body="Upgrading firmware on router $[/system identity get name] from $[/system routerboard get current-firmware] to $[/system routerboard get upgrade-firmware]"
      :log info ("Upgrading firmware on router $[/system identity get name] from $[/system routerboard get current-firmware] to $[/system routerboard get upgrade-firmware]")
      
      ## Wait for mail to be send & upgrade
      :delay 15s;
      upgrade

      ## Wait for upgrade, then reboot
      :delay 180s;
      /system reboot

   } else={

   :log info ("No Router HW upgrade found")

   }

}

Tenemos disponibles mas Scripts para Mikrotik para que te hagan la vida un poco más fácil.