2

I would like to change a Configuration in a Snap File (CodeMirror in the Notepadqq snap) so that I can change the syntax coloring for specific themes.

I know you cannot directly modify snap files, as it is read-only.

So if I wanted to do this, how could I manage doing this?

Rodrak
  • 21

2 Answers2

5

Actually there is a way around that. While we can't change a file in snap directly (without rebuilding it - that would be too hard), we can exploit mount's bind functionality to achieve the similar effect.

Caveat: I wouldn't recommend doing it permanently, but this can be invaluable for temporary debugging.

I will use certbot as an example. Its main.py file is located in /snap/certbot/952/lib/python3.8/site-packages/certbot/main.py. First we need to copy it somewhere:

$ cp /snap/certbot/952/lib/python3.8/site-packages/certbot/main.py /tmp/main.py

Then we edit the copied file:

$ echo 'print("no help for you!"); exit(1)' > /tmp/main.py

And now we mount the edited file over the original one:

$ mount -o ro,bind /tmp/main.py /snap/certbot/952/lib/python3.8/site-packages/certbot/main.py 

Test the results:

$ certbot --help
no help for you!

And when you are done, you can unmount the file:

$ umount /snap/certbot/952/lib/python3.8/site-packages/certbot/main.py

Again, I don't think this is very useful as a permanent solution - major updates to the underlying snap package will break something. If all you want to do is to change some configuration then using built-in configuration methods will be probably much easier and more maintainable.

If for some reason you still want to use this as a permanent solution, then you will need to tweak the idea to persist across reboots - store the changed file in some stable directory (not /tmp/), and make sure the mount happens during startup (I believe that it can be done using /etc/fstab entry).

Rogach
  • 605
2

Quite simply: you can't do this. Snaps are squashfs images, which are by definition read-only. There's no way around that. Reach out to the maintainers of the snap in question and request this functionality.

kyrofa
  • 7,502