[opensuse-factory] openSUSE and bash system profile loading issues
Hi, The idea is to throw a file into /etc/profiles.d/ and have everything available in every users environment without any specific ~/.profile or ~/.bashrc tweaking. Specifically, I want to define PS1, aliases and some functions. Unfortunately it doesn't work as advertised. Here's a subset of my trial (please ignore for now the way, I define the PS1 colors here, it should work in most terminals): cat > /etc/profile.d/test.sh << EOF # shell prompt if [ -n "$BASH_VERSION" ]; then set -P set -p if [ "$UID" = 0 ]; then PS1='\[\033[1;32m\]\h\[\033[1;36m\]:\[\033[1;31m\]\w\[\033[0;33m\]#\[\033[0m\] ' else PS1='\[\033[1;32m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;36m\]:\[\033[1;31m\]\w\[\033[0;33m\]>\[\033[0m\] ' fi export PS1 fi alias vi='vi -o' psg () { if [ $# -le 0 ]; then ps auxww | less else ps auxww | egrep "$@" | grep -v grep fi } export repo=/etc/zypp/repos.d EOF In theory, these should be available in every users environment. $repo is, the rest is not. After "su - $USER" or login via ssh all is well?!? Puzzled. So, there seems to be some environment tidying happen behind the scenes. Of course, I studied /etc/profile, /etc/bash.bashrc, and I can source this from ~/.bashrc. It will also not work, when sourced from ~/.profile. It might be, that PS1 is redefined from /etc/bash.bashrc, but why does it work from su - $USER or ssh then? psg() most definitely isn't redefined anywhere else. Anybody out there, who can shed some light into this issue would be much appreciated. Thanks in advance, Pete -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
/etc/profile and ~/.profile are only read by login shells. Andreas. -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different." -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Am Mittwoch, 26. Februar 2020, 17:33:00 CET schrieb Andreas Schwab:
/etc/profile and ~/.profile are only read by login shells.
Thanks, Andreas. Sure, and /etc/profile sources /etc/profile.d/*.sh as well as /etc/ profile.local. But it doesn't explain, why only fragments from settings of those files reaches the users environment, while a secondary login (with ssh or su -) is setup correctly. Thanks, Pete -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Wednesday 2020-02-26 18:54, Hans-Peter Jansen wrote:
Am Mittwoch, 26. Februar 2020, 17:33:00 CET schrieb Andreas Schwab:
/etc/profile and ~/.profile are only read by login shells.
Thanks, Andreas.
Sure, and /etc/profile sources /etc/profile.d/*.sh as well as /etc/ profile.local. But it doesn't explain, why only fragments from settings of those files reaches the users environment, while a secondary login (with ssh or su -) is setup correctly.
Because the smart people at SUSE have this: /etc/bash.bashrc: PS1="${_t}${_u}:\w${_p} " which means they reset and force their PS1 on you every time you start a subshell of any kind (because it's in bashrc rather than profile.d). -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
26.02.2020 21:17, Jan Engelhardt пишет:
On Wednesday 2020-02-26 18:54, Hans-Peter Jansen wrote:
Am Mittwoch, 26. Februar 2020, 17:33:00 CET schrieb Andreas Schwab:
/etc/profile and ~/.profile are only read by login shells.
Thanks, Andreas.
Sure, and /etc/profile sources /etc/profile.d/*.sh as well as /etc/ profile.local. But it doesn't explain, why only fragments from settings of those files reaches the users environment, while a secondary login (with ssh or su -) is setup correctly.
Because the smart people at SUSE have this:
/etc/bash.bashrc: PS1="${_t}${_u}:\w${_p} "
which means they reset and force their PS1 on you every time you start a subshell of any kind (because it's in bashrc rather than profile.d).
Smart people at SUSE also read /etc/bash.bashrc from within /etc/profile, and they also do not overwrite exported PS1 (read more carefully context around line you quoted). This would be too easy. -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
26.02.2020 19:18, Hans-Peter Jansen пишет:
Hi,
The idea is to throw a file into /etc/profiles.d/ and have everything available in every users environment without any specific ~/.profile or ~/.bashrc tweaking.
Specifically, I want to define PS1, aliases and some functions.
Unfortunately it doesn't work as advertised.
Here's a subset of my trial (please ignore for now the way, I define the PS1 colors here, it should work in most terminals):
cat > /etc/profile.d/test.sh << EOF # shell prompt if [ -n "$BASH_VERSION" ]; then set -P set -p if [ "$UID" = 0 ]; then PS1='\[\033[1;32m\]\h\[\033[1;36m\]:\[\033[1;31m\]\w\[\033[0;33m\]#\[\033[0m\] ' else PS1='\[\033[1;32m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;36m\]:\[\033[1;31m\]\w\[\033[0;33m\]>\[\033[0m\] ' fi export PS1 fi
alias vi='vi -o'
Aliases should be available for each interactive shell which means progile is simply the wrong place to set them.
psg () { if [ $# -le 0 ]; then ps auxww | less else ps auxww | egrep "$@" | grep -v grep fi }
export repo=/etc/zypp/repos.d EOF
In theory, these should be available in every users environment.
$repo is, the rest is not.
You do not say how user logs in, so it is rather hard to answer. Assuming you mean GUI session - /etc/profile is sourced by session script, which means only exported variables or functions are available in later subshells. Also depending on your exact DE environment may be inherited via systemd/D-Bus which may simply ignore exported functions which leaved only exported variables.
After "su - $USER" or login via ssh all is well?!? Puzzled.
So, there seems to be some environment tidying happen behind the scenes. Of course, I studied /etc/profile, /etc/bash.bashrc, and I can source this from ~/.bashrc. It will also not work, when sourced from ~/.profile.
It might be, that PS1 is redefined from /etc/bash.bashrc, but why does it work from su - $USER or ssh then?
Again, you do not say how you log in, but - PS1 is set only in interactive shells. For GNOME what happens is - gnome-session re-executes itself under login shell. This login shell exports PS1. Then gnome-session shebang shell unsets PS1 because it is non-interactive. gnome-session-binary uploads current environment into systemd which is where it comes from for your interactive gnome-terminals.
psg() most definitely isn't redefined anywhere else.
Anybody out there, who can shed some light into this issue would be much appreciated.
Thanks in advance, Pete
-- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Am Mittwoch, 26. Februar 2020, 21:12:37 CET schrieb Andrei Borzenkov:
26.02.2020 19:18, Hans-Peter Jansen пишет:
Hi,
The idea is to throw a file into /etc/profiles.d/ and have everything available in every users environment without any specific ~/.profile or ~/.bashrc tweaking.
Specifically, I want to define PS1, aliases and some functions.
Unfortunately it doesn't work as advertised.
Here's a subset of my trial (please ignore for now the way, I define the PS1 colors here, it should work in most terminals):
cat > /etc/profile.d/test.sh << EOF # shell prompt if [ -n "$BASH_VERSION" ]; then
set -P set -p if [ "$UID" = 0 ]; then
PS1='\[\033[1;32m\]\h\[\033[1;36m\]:\[\033[1;31m\]\w\[\033[0;33m\] #\[\033[0m\] '> else
PS1='\[\033[1;32m\]\u\[\033[0;36m\]@\[\033[1;32m\]\h\[\033[1;36m\] :\[\033[1;31m\]\w\[\033[0;33m\]>\[\033[0m\] '> fi export PS1
fi
alias vi='vi -o'
Aliases should be available for each interactive shell which means progile is simply the wrong place to set them.
I see, it that documented somewhere?
psg () {
if [ $# -le 0 ]; then
ps auxww | less
else
ps auxww | egrep "$@" | grep -v grep
fi
}
export repo=/etc/zypp/repos.d EOF
In theory, these should be available in every users environment.
$repo is, the rest is not.
You do not say how user logs in, so it is rather hard to answer. Assuming you mean GUI session - /etc/profile is sourced by session script, which means only exported variables or functions are available in later subshells. Also depending on your exact DE environment may be inherited via systemd/D-Bus which may simply ignore exported functions which leaved only exported variables.
Okay, sorry for omitting that important information. Yes, my primary target are DEs with KF5, running konsole.
After "su - $USER" or login via ssh all is well?!? Puzzled.
So, there seems to be some environment tidying happen behind the scenes. Of course, I studied /etc/profile, /etc/bash.bashrc, and I can source this from ~/.bashrc. It will also not work, when sourced from ~/.profile.
It might be, that PS1 is redefined from /etc/bash.bashrc, but why does it work from su - $USER or ssh then?
Again, you do not say how you log in, but - PS1 is set only in interactive shells. For GNOME what happens is - gnome-session re-executes itself under login shell. This login shell exports PS1. Then gnome-session shebang shell unsets PS1 because it is non-interactive. gnome-session-binary uploads current environment into systemd which is where it comes from for your interactive gnome-terminals.
Sounds complicated, but I suspect something similar obscure is going on for KF5 and konsole sessions. The here script from my initial submission allows inclined people to test this behavior themselves easily. I also see places in the initial scripts (/etc/profile and /etc/bash.bashrc, that specifically deal with the ssh login special case. I don't see similar obvious handling of, say su - handling, but both get it right, while konsole sessions do not. Again, my primary goal is supplying such system configuration at *one* place for all users and any DE (with focus on konsole), but failed to do so with *any* of the given possibilities including /etc/profile.local - without the need to adjust each and every user's .bashrc. Thanks for the insight, Andrei, much appreciated. Unfortunately, I still don't see any strategy, that might be successful. Any other ideas, how to archive that goal? Thanks, Pete -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
* Hans-Peter Jansen <hpj@urpla.net> [02-26-20 17:45]: [...]
The here script from my initial submission allows inclined people to test this behavior themselves easily.
I also see places in the initial scripts (/etc/profile and /etc/bash.bashrc, that specifically deal with the ssh login special case. I don't see similar obvious handling of, say su - handling, but both get it right, while konsole sessions do not.
Again, my primary goal is supplying such system configuration at *one* place for all users and any DE (with focus on konsole), but failed to do so with *any* of the given possibilities including /etc/profile.local - without the need to adjust each and every user's .bashrc.
Thanks for the insight, Andrei, much appreciated. Unfortunately, I still don't see any strategy, that might be successful. Any other ideas, how to archive that goal?
you might have a look at the hxtools packages. -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
27.02.2020 01:44, Hans-Peter Jansen пишет:
Again, my primary goal is supplying such system configuration at *one* place for all users and any DE (with focus on konsole)
What's wrong with /etc/bash.bashrc.local? -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Am Donnerstag, 27. Februar 2020, 21:04:19 CET schrieb Andrei Borzenkov:
27.02.2020 01:44, Hans-Peter Jansen пишет:
Again, my primary goal is supplying such system configuration at *one* place for all users and any DE (with focus on konsole)
What's wrong with /etc/bash.bashrc.local?
Will try that, thanks Andrei. Cheers, Pete -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Am Freitag, 28. Februar 2020, 16:18:23 CET schrieb Hans-Peter Jansen:
Am Donnerstag, 27. Februar 2020, 21:04:19 CET schrieb Andrei Borzenkov:
27.02.2020 01:44, Hans-Peter Jansen пишет:
Again, my primary goal is supplying such system configuration at *one* place for all users and any DE (with focus on konsole)
What's wrong with /etc/bash.bashrc.local?
Will try that, thanks Andrei.
Works like a charm. Thanks a bunch, Andrei, much appreciated. I've packaged this up in: https://build.opensuse.org/package/show/home:frispete:Tumbleweed/etc-LISA https://build.opensuse.org/package/show/home:frispete:15.2/etc-LISA https://build.opensuse.org/package/show/home:frispete:15.1/etc-LISA https://build.opensuse.org/package/show/home:frispete:15.0/etc-LISA It's a set of tools, mostly about convenience, eg. zyp, sc and jc aliases, that support bash completions properly, and other specialized tools for system administration and development, eg. obs-prj-diff to diff complete projects, and quilt is q now ;-). For the hardcore FF users out there, that suffer from trashed session setup, etc-LISA-gui contains a (new) tool to deal with that: wm-win-tool. In my initial setup, I'm running Firefox with 37 windows, scattered over 12 desktops. The tool allows to store a list of window geometries, desktop and shaded states, selected by name and class patterns, in order to restore this layout later on. Iow., cope with the issues, that Firefox suffers from since about 13 years now: https://bugzilla.mozilla.org/show_bug.cgi?id=372650 Since I use for my programming tasks mostly python3 these days, it's a python3 script of course. And one, that I shouldn't be ashamed of, hopefully... Comments welcome. Have a nice flight.. Cheers, Pete -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Hans-Peter Jansen wrote:
Hi,
The idea is to throw a file into /etc/profiles.d/ and have everything available in every users environment without any specific ~/.profile or ~/.bashrc tweaking.
Specifically, I want to define PS1, aliases and some functions.
Unfortunately it doesn't work as advertised.
While I have no idea why it doesn't, I've been bitten by that, too, before.
From my ~/.bashrc:
# This one defines aliases - they don't get through with the current SuSE setup # Read them again test -f /etc/profile.d/idl.sh && . /etc/profile.d/idl.sh No idea when I put that in - but for sure a long time ago. -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
participants (6)
-
Andreas Schwab
-
Andrei Borzenkov
-
Hans-Peter Jansen
-
Jan Engelhardt
-
Patrick Shanahan
-
Peter Suetterlin