Can ucode be used in uci-defaults?

Hi I'm trying to create customized images using firmware-selector that might contain some custom files, like custom scripts, etc. My idea is to convert all these files into a base64 string and use ucode to convert and write them into the disk. Something like this

#!/usr/bin/ucode

import { open, error, chmod } from 'fs';

files = [
	{ address: "/root/a.sh" , value: "IyEvYmluL2FzaAoKZWNobyAiaGVsbG8gd29ybGQhIgo=", mode: 0o644 }
];

for (f in files) {
	fp  = open(f.address, "w");
	fp.write(b64dec(f.value));
	fp.close();
	chmod(f.address, f.mode);
}

exit(0)

Now my questions are:

  • Can ucode script be used for this?
  • Do we have any limits on uci-defaults files? Either on image part or on firmware-selector part?

Thanks

For a file you can include it in a package. You can use ruby or perl if you have to.

Thanks for your answer.

Two more questions :sweat_smile:

  1. What do you mean by this?

include it in a package

I couldn't find any documentation around how to add a package from 3rd party package feed to the firmware-selector
I found the repositories field in /api/v1/build endpoint of the sysupgrade.openwrt.org docs
From the code that appears here I think custom repositories are not allowed at least in sysupgrade.openwrt.org

  1. why do you suggest to use ruby or perl instead of ucode which is already present in OpenWRT?

Yes, you should be able to use ucode-based uci-defaults scripts. The firewall code is all written in ucode and it's running about that same time during the boot sequence, so I don't see any reason it shouldn't work just fine. Give it a try and let us know if you see anything amiss...

1 Like

Oh, forgot that one. The ASU server restricts the size of the file to 20KB (20480 bytes), which shouldn't be an issue (if you need more space, just write a script, put it in /usr/bin or wherever, then have your uci-defaults run it).

1 Like

Thanks that clears up everything
So based on our discussion, what I will try to do is this:

  • if the files are relatively small, will embed them in uci-defaults
  • If they are big I will try to create a package and install it, either in image creation process or in uci-defaults