For automation purposes it would be useful to have a directory where "environment snippets" could be dropped without risking to interfere with other stuff on the same system. Having /etc/profile source /etc/profile.d/*.sh by default would provide such a facility, just like is being done on other operating systems. This would make my life as a Puppet user so much easier allowing me reuse the same code on different operating systems and it would be useful for package/ports maintainers too. I tested this snippets at the end of the stock /etc/profile and AFAIK it is working without any problem with both the standard sh shell and the ports-installed bash shell: # source *.sh files from /etc/profile.d if they are readable if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi
In which file did you inserted those lines? Have you tested it with tsch? How about the other shells offered by the ports?
I just saw that it was at the end of /etc/profile
Yes indeed it would go at the end of the already-provided /etc/profile. This way it should introduce no regressions of any kind and just provide new functionality if/when someone wants to use it. The current /etc/profile from FreeBSD sources says that it is "System-wide .profile file for sh(1)" so I did not bother to test it with tcsh, as far as I know tcsh does not use /etc/profile nor ~/.profile.
As someone who supports CentOS and FreeBSD in production, I'm potentially interested in this as well. It would simplify creating portable shell env customizations that work on both BSD and Linux. I wonder if there are security or stability concerns that someone might raise, though. A feature like this opens up the possibility of ports installing things that modify the default environment, unbeknownst to the sysadmin. If it goes forward, we would need checks in all the startup scripts, e.g. /etc/csh.cshrc, /etc/csh.login, /etc/profile, ... We might also want to check ${LOCALBASE}/etc/profile.d.
Support for /etc/profile.d would indeed be useful. When creating packages of software making customisations of the profile, it is helpful to have a per-package profile configuration, instead of having to merge things into a single /etc/profile file during installation. This particularly makes a safe and clean deinstallation difficult. Package installation -> add a package-specific file to /etc/profile.d Package removal -> remove the file
Some additions I would make to Luca's example: 1. Add ${LOCALBASE}/etc/profile.d 2. Make sure the profile.d directories and all scripts in them are owned by root:wheel and not group or world writable.
Looks like this has landed in base: https://cgit.freebsd.org/src/commit/bin/sh?id=497cdf9673ec53d59634bb78862cd8dea3d5c155
See 497cdf9673ec, d3890a547d20, 8d7221ca2dd5.