Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 679162 - sys-apps/baselayout: /etc/profile: Please source /etc/profile.d/* after setting PS1
Summary: sys-apps/baselayout: /etc/profile: Please source /etc/profile.d/* after setti...
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: William Hubbs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-01 16:39 UTC by bugs77
Modified: 2023-01-26 16:34 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bugs77 2019-03-01 16:39:54 UTC
I have set my own bash prompt PS1 in ~/bashrc, which works fine with login shells.

It also works when becoming root in a terminal with 'su'.
However, after issuing '. /etc/profile' for example as part of system maintenance, my custom PS1 returns to the default set by /etc/profile.
This is because ~/.bashrc is not sourced in this case.

My attempted solution to this was to set PS1 in /etc/profile.d/custom.sh instead of ~/bashrc. But this does not work because /etc/profile sets PS1 after sourcing
/etc/profile.d/*.

Would it be possible to source /etc/profile.d/* after setting PS1 in /etc/profile please?
This would allow system wide PS1 customization through /etc/profile.d/*.
Comment 1 Mike Gilbert gentoo-dev 2019-03-01 16:48:18 UTC
bashrc stuff really belongs after /etc/profile.d stuff. Setting PS1 belongs in bashrc.

I suggest you edit /etc/bash/bashrc, or source ~/.bashrc whenever you source /etc/profile.
Comment 2 bugs77 2019-03-03 18:46:10 UTC
I agree with PS1 stuff probably belonging into some *bashrc* file, but that does not solve my problem. And there is PS1 stuff in /etc/profile already and according to above reasoning, it schould not be there.
Actually, removing all PS1 stuff from /etc/profile solves my problem too.
But I have no idea why it ended up there in the first place, so I guess it is there for a reason and it is best to keep it there for now.

Editing /etc/bash/bashrc also does not solve my problem, none of the bashrc stuff
is read during . /etc/profile.
Of course, I could change /etc/profile and source ~./bashrc there or I could just apply the suggested bug fix myself.
But that defeats the whole purpose of /etc/*.d/ directories, which is to allow modification of system defaults, either by package management or the system administrator, without touching system files and having to deal with them after system upgrades.

/etc/bash/bashrc does it right, /etc/bash/bashrc.d/* is sourced right at the end, /etc/profile should do it the same way.

/etc/profile.d/* allows modification of everything except for PS1, which I consider a bug.
Comment 3 bugs77 2019-03-04 12:03:04 UTC
Edit: Setting my PS1 in /etc/bash/bashrc.d/* actually solves my problem because the PS1 stuff in /etc/profile sources /etc/bash/bashrc conditionally.
Thanks for pointing me in the right direction.
But I think the rest of my argument is still valid, /etc/profile.d/* should be sourced at the end of /etc/profile.
Comment 4 Evert 2020-04-01 09:55:56 UTC
In the past, I have researched this in detail.

A bash login shell (bash -l) sources
- /etc/profile
- ~/.bash_profile

A bash (non-login) shell (bash) sources
- /etc/bash/bashrc
- ~/.bashrc

In case of a login shell, it's up to /etc/profile and/or ~/.bash_profile to also source the non-login shell parts *afterwards*, so
/etc/profile
  /etc/profile.env
  /etc/profile.d/*.sh
  /etc/bash/bashrc
    /etc/bash/bashrc.d/*.sh
---------------------------
~/.bash_profile
  ~/.bashrc

In your case, when you only source /etc/profile, you simulate only half of the login shell process. This is your problem (if I understand correctly). To simulate a full login shell, you should additionally source ~/.bash_profile,  so:
source /etc/profile
source ~/.bash_profile

As an alternative, you can simply start a new login shell (which does a source of both), so:
exec bash -l
Comment 5 William Hubbs gentoo-dev 2023-01-26 16:34:22 UTC
There doesn't appear to be anything to fix in this bug since the
previous two comments have explained the proper place to set PS1.