Automagically reboot Mikrotik router from OSMC

Posted on Thu 05 April 2018 in Automatyczny dom

Personas:
192.168.10.1- MikroTik home router with Internet connection and WiFi LAN
192.168.10.6- Raspberry Pi with OSMC media center OS (based on Kodi)
Login to OMSC
Generate key without password:
  1. 2ssh-keygen -t dsa
Transfer public key to Mikrotik router.
  1. 2scp ~/.ssh/id_dsa.pub osmc@192.168.10.1:.
Login to MikroTik router:
Add special group for remote users:
/user group add name="remote_ssh" policy=ssh,reboot,!local,!telnet,!ftp,!read,!write,!policy,!test,!winbox,!password,!web,!sniff,!sensitive,!api,!romon,!dude skin=default
Add new user into „remote_ssh� group:
/user add name=osmc group=remote_ssh password=****** comment='osmc user'
Import public key for „osmc� user:
/user ssh-keys import file=id_dsa.pub user: osmc
Login back into OMSC:
ssh osmc@192.168.10.6
Create shell script called "mikrotik-osmc.sh�:
cat << EOF > http://mikrotik-osmc.sh
press <Enter> and paste following text:
  1. 2#!/bin/sh
  2. 4# script reboots Mikrotik home router
  3. 6xbmc-send -a "Notification(MikroTik,Rebooting router...)"
  4. 8ssh -l osmc -i ~/.ssh/id_dsa 192.168.10.1 "/system reboot"
press <Enter>, write „EOF� (without quotes) and press <Enter> again. You will find „mikrotik-osmc.sh� file in current directory.
Make this script executable:
  1. 2chmod +x mikrotik-osmc.sh
You can now logout from OSMC ssh session. Following steps we will perform using OSMC GUI with keyboard or remote.
I couldn’t find a way to run my script from GUI in OSMC default skin. Also couldn’t find it in Confluence skin so I decided to install Aeon Nox skin which has such feature built in.
Installing Aeon Nox is easy:
In OSMC GUI go to:
Settings->Add-ons
chooseInstall from repository(v15/v16) /Get add-ons(v14)
selectKodi add-on repository
chooseLook and feel(v16 and higher)
thenSkins
selectAeon Nox
and finallyInstall
Now go back toSettings->Appearance->
fromSkinsubmenu selectAeon Noxand confirmYes.
New skin should be loaded now.
Now you can add new item on the Start Screen that will allow you to reboot your router.
Disclaimer: this will only work if network connection between your OSMC and your router is still working but only WAN (Internet) connection is down.
FromStart Screengo toSystem->Skin
selectSettings
fromHome WindowselectSetup the Aeon Nox main menu.
In left column selectCUSTOM1and in the right column selectDefault select action:
In the following window select Custom Item and in keyboard input write:
  1. 2System.Exec(/home/osmc/mikrotik-osmc.sh)
and press <Enter>.
Go to Edit label and name it Reboot Router.
Be sure that option Enabled is turned on.
Go back to Start Screen and you should find new Reboot Router option. Select it and you sould see notification and after few second your MikroTik should restart.
Inform all members of your family about this item.
Usefull links:
Execute commands with SSH on MikroTik:

http://wiki.mikrotik.com/wiki/Us...

Full list of Kodi commands:

http://kodi.wiki/view/List_of_bu...