CAPsMAN how to keep .npk updated ? (Cap Manager auto-update)

With CAP “require same version” upgrade policy, how can I keep .npk files for APs, AUTOMATICALLY updated to same version (latest) before I update manager ?

Thanks

Hi
I don’t understand your request.

If you want to use upgrade policy require same version, is because you will put in manager files the latest version of RouterOS
/caps-man manager
set enabled=yes package-path=/upgrade/routeros-mipsbe-6.41.3.npk

Important create a folder where you will upload the file, it won’t work from root folder.

Regards.

Basically I need to update .npk file for APs AUTOMATICALLY before Manager upgrade.
Copying and mixing parts from some sources and wiki I’m ended with this simple working script :


############# create ap file directory: "apdir"

############# create the update schedule:

/system scheduler
add name=AutoUpdate start-date=apr/25/1970 start-time=04:00:00 interval=1d on-event=Update

#############   name the following script: "Update"   

/system package update
check-for-updates once

:delay 3s;

:if ( [get status] = "New version is available") do={ 

:local newVer [get latest-version]
/tool fetch address="download.mikrotik.com" mode=https src-path="/routeros/$newVer/routeros-mipsbe-$newVer.npk" dst-path="/apdir"
/tool e-mail send to="user@domain" 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])"
   
:delay 5s;
   
install

} else={

/system routerboard

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

/tool e-mail send to="user@domain" 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]"
      
:delay 5s;

upgrade

:delay 5s;

/system reboot

}
}

Script does also a firmware check and upgrade if package is already updated.
I don’t know if pauses are really needed…
Once manager has rebooted with newest version, the relative file for APs is present on the “apdir” directory (that must be declared in /caps-man manager set package-path) and all APs will upgrade accordingly.
The downloaded file must match the APs architecture that can be different from Manager one.

Any suggestion or modification is well accepted :smiley:

I am wary of automatic upgrades, I have been bitten more than once. I am no scripting guru either, that’s mostly why took a look at your script. Two observations:

  1. The last closing brace doesn’t have a pair.
  2. With your logic the firmware will be updated on the next run (24h hours later) - unless there is a new package update. I don’t follow the reasoning for the else clause.

Very probably I’m less expert in scripting than you… :smiley:
A said , I’ve copied some sources, and that sequence was done that way , probably , yes , it can be modified to do a firmware check and upgrade once routerboard has rebooted after a package upgrade (so I don’t bother so much…new package today ? we will check firmware tomorrow… :laughing: )
Unless it is so important to have firmware upgraded before package , someone experienced will tell us.

Braces are paired this way:

else={
/system routerboard
:if ( [get current-firmware] != [get upgrade-firmware]) do={

blablabla

}
}

About automatic update, yes one has to rely in mikrotik staff hard work.
As the main goal is to have APs .npk file updated before the manager is (mandatory in case of “require same version”) , it can be ran manually when needed, simply by omitting schedule.

I’ve added some code to remove the old file so you wont accumulate npk’s until your disk is full
Execute it before you download the new npk

:local oldNpk [file find name ~“routeros-”]
/file remove $oldNpk