1. Check for new version of RouterOS
2. If new version is availible - send notification
3. If new version is availible - download and install new version
4. If new version is availible - reboot running instance
5. If new version is availible - check firmware version
6. If new version is availible - upgrade firmware
7. If new version is availible - reboot and send notification
Solution, which worked for me:
At the first point, I set up e-mail configuration for sending notification. Because there may be problems with internal mail server, I choose to use gmail. In scripts I also use Identity and current time:
ros code
/tool e-mail set address=173.194.70.108 from="Sender Name <anything@gmail.com>" \ password="Password" port=587 start-tls=yes user=anything@gmail.com /system clock set time-zone-name=Europe/Prague /system identity set name=NAME /system ntp client set enabled=yes primary-ntp=217.31.205.226 secondary-ntp=195.113.144.201We must take all process backwards. So we must send notification about successful RouterBoard firmware upgrade:
ros code
/system scheduler add comment="Send SMS when upgrade was successful" disabled=yes name=\ send-sms-succesful-upgrade on-event=":delay 60s;\r\ \n/tool e-mail send to=\"some@email.eg\" body=\"\" subject\ =\"RouterOS \$[/system identity get name] successfuly upgraded\";\r\ \n/system scheduler disable send-sms-succesful-upgrade;" policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ start-time=startupAt the next we must make very simple script for firmware upgrade. Another solution isn't possible, because when you're upgrading firmware you will be asked for answer on question about confirmation upgrade.
ros code
/system script add name=upgrade-bootloader policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ source="/system routerboard upgrade"Next we make schedule for firmware upgrade:
ros code
/system scheduler add comment="Auto upgrade bootloader" disabled=yes name=auto-upgrade-bootloader \ on-event=":delay 100s;\r\ \n/system scheduler disable auto-upgrade-bootloader;\r\ \n/system routerboard\r\ \n:global current [get current-firmware];\r\ \n:global latest [get upgrade-firmware];\r\ \n:if (\$current != \$latest) do={ /tool e-mail send to=\"some@email\ .eg\" body=\"Performing bootloader upgrade from \$current to \$latest\" sub\ ject=\"\$[/system identity get name] \$[/system clock get date] \$[/system c\ lock get time] performing bootlader upgrade\"; /system scheduler enable send\ -sms-succesful-bootloader-upgrade; /system script run upgrade-bootloader; /\ system reboot; }" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ start-time=startupNext we make schedule for alert about successful RouterOS upgrade:
ros code
/system scheduler add comment="Send SMS when upgrade was successful" disabled=yes name=\ send-sms-succesful-upgrade on-event=":delay 60s;\r\ \n/tool e-mail send to=\"some@email.eg\" body=\"\" subject\ =\"RouterOS \$[/system identity get name] sucessfuly upgraded\";\r\ \n/system scheduler disable send-sms-succesful-upgrade;" policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ start-time=startupFinally we make scheduler task for checking new RouterOS, upgrade and so on. Actually we setup task to run once a week at night Monday/Tuesday at 4:00 AM
ros code
/system scheduler add comment="Auto upgrade RouterOS Monday/Tuesday 4:00AM" interval=1w name=\ auto-upgrade on-event="/system package update\r\ \ncheck-for-updates\r\ \n:delay 1s;\r\ \n:global current [get current-version];\r\ \n:global latest [get latest-version];\r\ \n:if (\$current != \$latest) do={ /tool e-mail send to=\"some@email\ .eg\" body=\"Performing upgrade from \$current to \$latest\" subject=\"\$[/\ system identity get name] \$[/system clock get date] \$[/system clock get ti\ me] performing upgrade\"; /system scheduler enable send-sms-succesful-upgrad\ e; /system scheduler enable auto-upgrade-bootloader; upgrade; }" policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ start-date=mar/18/2014 start-time=04:00:00