Executing a custom script during Openwrt Image creation

Hi
I am trying to execute a custom script that creates files in specific location in the rootfs. Im trying to invoke it from include/rootfs.mk after the symlink creation step but i don't see the script getting executed. Tried to add an extra fucntion in rc.common and call that function from rootfs.mk (similar to how the symlink creation step is being invoked from rootfs.mk), but still could not do it.
I cannot use the package/base-file method as i need a script to do it as there are some conditions that need to be validated before creating the files i need.
Thank you

May be, to include your script in files/etc/uci-defaults, to be run only once on first boot after flash.

HI @reinerotto ,

Yeah, that works only if i want to execute the script after i flash the image on the device. But my requirement is to run the script at the image compilation time.

... which will be very version dependent. A nightmare to maintain.

Does your script depend on build artifacts midway through the build or something? If not, just run the script before you run make...

1 Like

makefiles are in fact scripts themselves, you can execute shell commands from the makefile during compilation. Its quite common, for example to git the git version, theres plenty of info on the net reguarding this topic so i would go into great detail.

Aa quick example, one could grab the git reversion and stash in in a variable to be use in the make as needed, like this

GIT_SHA_FETCH := $(shell git rev-parse HEAD | cut -c 1-8)
export GIT_SHA=$(GIT_SHA_FETCH)

git_sha:
    @echo GIT_SHA is $(GIT_SHA)

Hostle

perhaps a more suitable solution ...use cmake. There is oodles of info on how to create a simple CMake.list to do just what you are trying to accomplish. make or cmake .. It all depends on how you take your coffee :slight_smile: