bash: define SSH_SOURCE_BASHRC
This makes bash agree with its documentation at https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
Bash attempts to determine when it is being run with its standard
input connected to a network connection, as when executed by the
historical remote shell daemon, usually rshd, or the secure shell
daemon sshd. If Bash determines it is being run non-interactively in
this fashion, it reads and executes commands from ~/.bashrc, if that
file exists and is readable. [...]
Notes:
- Disabled by upstream in 2.05a (2001), manual never changed
- This is enabled in Debian, Fedora, Gentoo, ...
To avoid this feature, add
[[ $- != *i* ]] && return
to the top of ~/.bashrc to skip running it in non-interactive mode.
Testing the changes
- I tested the changes in this PR: YES
Note also that the DEFAULT_PATH_VALUE is set to
"/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."
I wonder if we should remove the trailing . there and/or reorder to match our /etc/profile.
This default path applies only if PATH is unset when starting bash as in
$ env -i bash -c 'echo $PATH'
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.
The following would "fix" the default PATH in bash (to exclude .):
--- a/srcpkgs/bash/template
+++ b/srcpkgs/bash/template
@@ -24,7 +24,11 @@ alternatives="
sh:sh:/usr/bin/bash
sh:sh.1:/usr/share/man/man1/bash.1"
-CFLAGS="-DSSH_SOURCE_BASHRC -DNON_INTERACTIVE_LOGIN_SHELLS -DSYS_BASHRC='\"/etc/bash/bashrc\"'"
+CFLAGS="\
+ -DSSH_SOURCE_BASHRC \
+ -DNON_INTERACTIVE_LOGIN_SHELLS \
+ -DDEFAULT_PATH_VALUE='\"/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin\"' \
+ -DSYS_BASHRC='\"/etc/bash/bashrc\"'"
post_install() {
rm -r ${DESTDIR}/usr/share/doc
It's not a very common situation to start bash with unset PATH, so this is not that important.
On the other hand, adding -DSSH_SOURCE_BASAHRC is IMHO very, very, necessary, and the only way (afaik) to have a reasonable bash startup that works fine with ssh (e.g. to setup PATH, etc).
I'm torn about this. On the one hand, I've often been frustrated working around default PATH settings to get access to remote executables in non-standard locations. On the other hand, having a non-interactive shell source the interactive configuration seems a bit skeevy.
I'm not sure about a reasonable alternative. The closest one is:
- set
PermitUserEnvironment BASH_ENVinsshd_config(needs root) - set
BASH_ENV=~/.bashrcin~/.ssh/environmentHowever, this will end up running~/.bashrcalso in subshells, which is not what we want.
The original feature, when SSH_SOURCE_BASHRC is set, will source ~/.bashrc only when SHLVL=1, so in principle it will only get run once per ssh.