How to patch file from another package

I need to replace (or modify) the /lib/upgrade/platform.sh file. The discussion in previous question was helpful, and it was working for the 21.02 version.

I now compile more recent version and trying replacing the file causes make saying

* check_data_file_clashes: Package kernel_my wants to install file /home/.../lib/upgrade/platform.sh
	But that file is already provided by package  * base-files

Which is actually logical and understandable.

  1. I am curious why compilation of 21.02 replaces this file without issues - are there any flags to set resolving this issue?
  2. What is the right way to have new/modified platform.sh, provided by my package, in the compiled image? This is very important not to have it "installed" after system powers up, but have the right version in the ROM.

Edit: I think I can just replace the source file in original location (in its package), but then it will not be portable at all, and not clear how to document it properly.

generally you add your device specific functions and variables to the platform.sh of the target platform. If its something custom you need to set it up in a non invasive way that targets your device and what ever condition is to be met to fire these customs functions.
Usually some simple logic is enough to accomplish this ..ie

 if [ "$board" = "my_device" ] && [ $some_condition = true ]; then
      do_my_custom_functions $some_condition
 fi

it depends on the complexity of the task. You could also use an external script and call it into your target platform.sh by referencing it at the top of the platform.sh file like so

. /path/to/my_custom_functions.sh

Modifying base-files scripts from another package sounds dangerous, especially when taking about sysupgrade functionality etc. that is really core.

As you want to modify a script, one way is post-install script for the package. That is run also when the package is installed in the firmware compilation.

See examples in https://github.com/search?q=repo%3Aopenwrt%2Fpackages+postinst+language%3AMakefile&type=code&l=Makefile

Some time ago I was playing with post install scripts and files replacement, and concluded (maybe erroneously) that during sysupgrade the file platform.sh is used NOT from the /lib/upgrade location, but from the ROM image - the one which was not post-install-overwritten.

Well, the /rom is the firmware image. If you have included the package in the firmware image, the modification should have been done during postinst run during compilation.

/rom can't be modified during runtime.

1 Like

Oh my... got it

define Package/mypackage/postinst
[ -z "$${IPKG_INSTROOT}" ] ||
{
	# run on host machine
	cp -f "$${IPKG_INSTROOT}/etc/mypackage/upgrade/platform.sh" "$${IPKG_INSTROOT}/lib/upgrade/platform.sh" 
}
endef

Correct?

hold my beer: [facinstall] Package for easy installation factory images

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.