In a nutshell, I'm trying to replace some image resources in one of the apps. Overwriting the files manually does the job, but every time the app updates, all my changed files are replaced by the original ones. I'm not sure if the resource files are overridden by dpkg or by the app itself when it first runs after updating. Setting the files as Read-Only doesn't seem to help as the app or dpkg manages to remove the readonly flag and replace the files anyway.

To be more specific, the app I'm trying to customise is "Plex Media Server" which doesn't have any official way of changing the DLNA icons. The icon though can be found under "/usr/lib/plexmediaserver/Resources/Graphics/dlna-icon-260.png", and when manually replaced is shown correctly in Plex and all devices that connect to it. But when I update the Plex software all my changes are replaced again by the original files.

So one way I can think of working around this, is to just to write a small shell script that replaces the resources again to my custom ones, and I can run it after each update. But I'm trying to find out if there is some better, proper or more automatised way to do this.

Being as best "hypotetic" case a way to make the linux system to return always my content when the file is read, while still allowing the file to be virtually written, deleted or created, but always return my content no matter what.

So my question is: Is my "best hypothetic case" possible to be implemented in Linux? Or how to prevent the files to be overwritten by dpkg?

Greetings and thanks.

closed as unclear what you're asking by G-Man, Ipor Sircer, Anthony Geoghegan, Stephen Rauch, Jeff Schaller Nov 9 '17 at 0:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Do you want a solution for your "update issue" or to your actual question? I don't think I did understand what you asked, but for me there are 2 different requests there. – Zip Nov 8 '17 at 18:24
  • 3
    You can make the files immutable (chattr +i), but then the application update will probably throw an error when it is unable to replace the file(s). This is sounding like an X-Y problem. What is the problem you're actually trying to solve? – DopeGhoti Nov 8 '17 at 18:27

The solution here depends a lot on your application's configuration flexibility, and the features your package manager has. Bear in mind that, if the paths change, you might suddenly end up with a non-working application.

Most programs allow you to do overrides for paths using a configuration file, maybe you can specify your own directory for the images here. Otherwise, maybe your application looks in a particular directory for these images before looking at its default image directory, which contains the images it installs by default. If you can use one of these application supported methods, you should.

If you can't, I'd avoid trying to stop the replacement of the file (for example, with chattr +i), because it will likely result in your package manager exiting with an error when it tries to update the package in future.

The better way is to cooperate with your package manager to achieve the result you want. For example, you can try one of the following:

  • In your package manager, tell it to not extract these files when performing installation. In pacman, for example, you can do something like this:
% cat /etc/pacman.conf
NoExtract = usr/lib/my_image_dir/* usr/lib/my_image_dir_2/* 
  • In your package manager, set a hook to replace the files after installation/upgrade of the package which provides these files. In pacman, for example, you can do this with a hook that looks something like this:
% cat /usr/share/libalpm/hooks/replace-images.hook
Type = Package
Operation = Upgrade
Target = the_package_to_target

Description = Replacing images
When = PostTransaction
Exec = /usr/bin/script_to_replace_images

If neither of these are possible, perhaps you can run your application with an overlay when it runs, in a mount namespace that is only visible to the application. This would satisfy your package manager as it never sees the overlay, and it would satisfy your needs as you could have only your replacement images in the overlay.

Not the answer you're looking for? Browse other questions tagged or ask your own question.