What is the official Debian/Ubuntu way to install new configuration files in user directories?
Solution 1:
I'm not sure about official recommendations for creating per-user configuration during package installation, but links I found certainly discourage it. However, if I was installing your package then this is my opinion on how I'd like it designed.
Installing configuration files
Many programs will first check a global configuration location (e.g. /etc/my_program
) before checking a per-user configuration (e.g. ~/.my_program
). When possible, the configuration should be placed at the global location.
Your concrete example of installing a per-user configuration file for ~/.lessfilter
is interesting because that does not have a global configuration file option. In this case, if you are providing the package my_package
then it could
- create a global configuration at
/usr/share/my_package/lessfilter
- add a script
/etc/profile.d/my_package
with content like
[ -f "${HOME}/.lessfilter" ] || cp /usr/share/my_package/lessfilter "${HOME}/.lessfilter"
This would allow a lot of flexibility. An obvious downside is that /etc/profile
might only affect interactive Bash sessions, and you may need to support other scenarios.
Links
- https://unix.stackexchange.com/questions/413484/why-dont-package-managers-have-per-user-installations-and-registries
- https://unix.stackexchange.com/questions/181618/placing-things-in-a-users-home-directory-with-deb
- https://www.reddit.com/r/debian/comments/hbce9i/adding_a_file_in_home_directory_in_deb_package/