Bootstrap download running multiple times?

I am trying to download a configuration alter file to a mikrotik router on first time connection. I used the below code in the bootstrap file, but it seems to download and run over and over, how do I make this only run once.

declare("Downloads.[FileType:3 Vendor Configuration File]", {path: 1}, {path: 1});
declare("Downloads.[FileType:3 Vendor Configuration File].FileName", {value: 1}, {value: "bootstrap.alter"});
declare("Downloads.[FileType:3 Vendor Configuration File].Download", {value: 1}, {value: Date.now()});

There are two ways of doing this. One is by enumerating through the values that come back from declare("Downloads.[FileType:3 Vendor Configuration File]", {value: 1}) and compare the desired vs expected values. I don’t like this approach as it can cause CPEs to go through unnecessary upgrades, for example if you buy your CPEs from a VAR and change the config file the VAR puts on them over time, you have no real way of knowing which version of the config file each CPE has.

The way I do this is fine a field in the config file and smuggle a known value in. For example, on various version of the SmartRG CPEs, I will use one of the following fields (CPE firmware dependent on which fields are available):

  • InternetGatewayDevice.DeviceInfo.X_SMARTRG_COM_Origin
  • InternetGatewayDevice.DeviceInfo.X_CLEARACCESS_COM_Origin
  • InternetGatewayDevice.DeviceConfig.PersistentData

For Zxyel’s, I use

  • Device.X_ZYXEL_System_Info.Contact

Then I have a vparam called ConfigOrigin that abstracts away pulling the value from the correct field for the different CPE version.

In these fields, I put Company Name v1. In my firmware upgrade provision I check if the CPE version has the desired value in that field, and if not push out a new config file.

Heres my vparam script:

let keys = [
    'InternetGatewayDevice.DeviceInfo.X_SMARTRG_COM_Origin',
    'InternetGatewayDevice.DeviceInfo.X_CLEARACCESS_COM_Origin',
    'InternetGatewayDevice.DeviceConfig.PersistentData',
    'Device.X_ZYXEL_System_Info.Contact'
];

return {writable: false, value: [getParameterValue(keys), "xsd:string"]};

function getParameterValue(keys) {
    for (let key of keys) {
        let d = declare(key, {value: Date.now()});

        for (let item of d) {
            if (item.value && item.value[0]) {
                return item.value[0];
            }
        }
    }

    return '';
}

Thank you so much!

This is actually going to help me on a few other things as well as I didn’t even consider version control.
I found my problem was actually because I put the statement in the default bootstrap which seems to run on the boot event, which is returned every time the file is run

All i needed to do was add an event to the provision of 0 BOOTSTRAP. That solved the issue initially, but Im going to add a field to accommodate for versioning so I can check to see what is done.

Glad I could help out! I originally started out just putting our company name in the field so I would have proof positive that the CPE was in our desired default state. Then quickly learned what a genius I had been when we needed to rev the config.