Bug 229473 - support /etc/profile.d by default for sh environment snippets
Summary: support /etc/profile.d by default for sh environment snippets
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-02 13:40 UTC by Luca Lesinigo
Modified: 2019-06-13 05:16 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luca Lesinigo 2018-07-02 13:40:45 UTC
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
Comment 1 Roberto Fernandez Cueto 2018-07-03 08:23:42 UTC
In which file did you inserted those lines?
Have you tested it with tsch?

How about the other shells offered by the ports?
Comment 2 Roberto Fernandez Cueto 2018-07-03 08:27:58 UTC
I just saw that it was at the end of /etc/profile
Comment 3 Luca Lesinigo 2018-07-03 16:51:31 UTC
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.
Comment 4 Jason W. Bacon freebsd_committer 2018-10-04 15:57:56 UTC
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.