kwindrem / SetupHelper

Helper functions to simplify writing setup scripts that modify VenusOs functionality. The package includes automatic reinstallation of the package after a VenusOs update.
153 stars 18 forks source link

Allow multiple packages to modify the same file #73

Open kwindrem opened 2 months ago

kwindrem commented 2 months ago

From here: https://github.com/Lucifer06/RemoteGPIO/issues/13

Hi Kevin, may I introduce the request for an additional way to modify files during setup? There are some cases that may require multiple packages to update the same file. For instance /etc/udev/rules.d/serial-starter.rules were it is required to add more lines in this configuration file. It would make sense to let various package to update that file than trying to manage conflicts. Also it would be nice then if PackageManager keep track of what was added by which Package. What do you think? Should I open this topic as an "issue" in kwindrem/SetupHelper to discuss further?

Recent changes in SetupHelper do record which package replaces a file. The information is stored in the same directory as the active file so it's not easy to collect. The three fileList files in each package directory list all FILES that get replaced so it might be easier to scan these lists. I also create a list of installed files and services when a package is installed. These might provide a more accurate indication of what files were replaced since they are built by updateActiveFile and installService.

As far as u-dev rules: All rule files in the rules folder are evaluated regardless of device type. I do this with VeCanSetup, adding VeCanSetup.rules for anything I wish to control. So there really is no need to modify it unless you need to REMOVE a rule. You can simply add another rules file.

I have recently added a way to patch files rather than replace them. If you can generate a patch file that works on all versions then this can be used, but the patched result still replaces the stock file which gets back to the original problem. If someone can suggest a way to modify the whatever file exists even if other packages modify it first, I'd be willing to add that to SetupHelper. Remember that the patch file needs to work on all Venus OS versions supported by the package AND work with other packages that modify the same file. That's lots of regression testing!!!

/u-boot/config.txt is one case where multiple packages need to add their own lines. Currently I handle this in the setup script and use sed to add lines during install and remove them during uninstall. I do not use updateActiveFile at all and it's not in the file lists. I can't think of a consistent way to automate this mechanism but would welcome the discussion.

In the early days of SetupHelper I used sed to make file modifications but building the sed commands proved difficult. Recently I played with patch which uses diff to create a patch file that is then applied to the original to make the modifications. I discovered that I still needed different patch files for different versions and creating/testing the patch files took far longer than editing a replacement by hand.

I invite anyone with ideas to contribute. Thanks.

kwindrem commented 1 month ago

A version of SetupHelper supporting multiple packages modifing the same file is now in beta. Set SetupHelper's branch/tag to 'beta' to get this version (currently v8.0~2). Please only do this if you have ssh access since you will need it to recover should a failed install or uninstall render the GUI unavailable (white screen).

I need your help: This needs considerable testing before releasing to the wild since a failed install or uninstall could result in an unrecoverable system (without ssh access which many do not have). With this change, ORDER of package installs and uninstalls is a factor in a successful operation -- mostly the uninstall. Please experiment with installs and uninstalls in various orders to insure there are no problems.

Modifications are done through the unix patch mechanism. Prior to this version, patched files always replaced the active file which prevented multiple packages from modifying the same file. With this change, the active file is now "patched in place" allowing one package to modify the file even if it had been modified by another. Uninstalling a patched file is also done through a "reverse patch" which attempts to undo a previous patch.

Patch has some limitations: one modification can not modify the same section of code modified by another package. This includes the "context" lines surrounding the actual change. In this case the patch would fail, so the install will be prevented.

Failing to reverse patch an active file is a critical failure since this could render the system unresponsive or with a GUI white screen. ssh access would then be needed to recover. Therefore, if an unstall failure occurs the active file is restored to the "original" backup made before any modifications. ALL MODIFICATIONS FROM OTHER PACKAGES MODIFYING THE FILE WILL BE LOST and those packages would need to be reinstalled. This should prevent an unresponsive system at the expense of other package functionality.

This version allows multiple patch files for each active file. Patch file names are of the form: PageSettings.qml-1.patch, PageSettings.qml-2.patch, PageSettings.qml-foo.patch, PageSettings.qml-bar.patch The "suffix" is unrestricted and can be used to label your patches in a meaningful way if desired. Each variant of the patch file is tested until one is found that works. If none are found, this is reported so a future install can be blocked.

updatePackage now also checks all patch file variants, and creates .patch files if original and result files are provided. Note the names have changed: .source -> .orig, .edited -> basename+suffix. See SetupHelper's PatchSource for the new format.

Please report any issues (log files will generally be helpful). I'ma also interested in your suggestions on how to make this better.

Thanks in advance.