GNU bug report logs - #29035
.bashrc updates

Previous Next

Package: guix-patches;

Reported by: Marius Bakke <mbakke <at> fastmail.com>

Date: Fri, 27 Oct 2017 23:51:02 UTC

Severity: normal

Done: Marius Bakke <mbakke <at> fastmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 29035 in the body.
You can then email your comments to 29035 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Fri, 27 Oct 2017 23:51:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Marius Bakke <mbakke <at> fastmail.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Fri, 27 Oct 2017 23:51:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Marius Bakke <mbakke <at> fastmail.com>
To: guix-patches <at> gnu.org
Subject: .bashrc updates
Date: Sat, 28 Oct 2017 01:50:28 +0200
[Message part 1 (text/plain, inline)]
Hello Guix!

These patches changes the default .bashrc so that it always sources
/etc/profile when the shell is non-interactive, and promptly exits after
that.

Marius Bakke (2):
  skel: Test for interactive shell instead of $SSH_CLIENT in .bashrc.
  skel: Return early from .bashrc when the shell is non-interactive.

 gnu/system/shadow.scm | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

-- 
2.14.3
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Fri, 27 Oct 2017 23:55:01 GMT) Full text and rfc822 format available.

Message #8 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: Marius Bakke <mbakke <at> fastmail.com>
To: 29035 <at> debbugs.gnu.org
Cc: Marius Bakke <mbakke <at> fastmail.com>
Subject: [PATCH 1/2] skel: Test for interactive shell instead of $SSH_CLIENT
 in .bashrc.
Date: Sat, 28 Oct 2017 01:53:56 +0200
* gnu/system/shadow.scm (default-skeletons): Instead of testing for
$SSH_CLIENT, check whether '$-' includes the letter 'i'.
---
 gnu/system/shadow.scm | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 236807c70..475960b89 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -157,12 +157,11 @@ if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n"))
 # honor it and otherwise use /bin/sh.
 export SHELL
 
-if [ -n \"$SSH_CLIENT\" -a -z \"`type -P cat`\" ]
+if [[ $- != *i* ]]
 then
     # We are being invoked from a non-interactive SSH session
-    # (as in \"ssh host command\") but 'cat' cannot be found
-    # in $PATH.  Source /etc/profile so we get $PATH and other
-    # essential variables.
+    # (as in \"ssh host command\").  Source /etc/profile so we
+    # get $PATH and other essential variables.
     source /etc/profile
 fi
 
-- 
2.14.3





Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Fri, 27 Oct 2017 23:55:02 GMT) Full text and rfc822 format available.

Message #11 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: Marius Bakke <mbakke <at> fastmail.com>
To: 29035 <at> debbugs.gnu.org
Cc: Marius Bakke <mbakke <at> fastmail.com>
Subject: [PATCH 2/2] skel: Return early from .bashrc when the shell is
 non-interactive.
Date: Sat, 28 Oct 2017 01:53:57 +0200
* gnu/system/shadow.scm (default-skeletons): Add return statement.
---
 gnu/system/shadow.scm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 475960b89..8d8dbc70a 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -163,6 +163,9 @@ then
     # (as in \"ssh host command\").  Source /etc/profile so we
     # get $PATH and other essential variables.
     source /etc/profile
+
+    # Don't do anything else.
+    return
 fi
 
 # Adjust the prompt depending on whether we're in 'guix environment'.
-- 
2.14.3





Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Sat, 28 Oct 2017 07:58:02 GMT) Full text and rfc822 format available.

Message #14 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Marius Bakke <mbakke <at> fastmail.com>
Cc: 29035 <at> debbugs.gnu.org
Subject: Re: [bug#29035] [PATCH 1/2] skel: Test for interactive shell instead
 of $SSH_CLIENT in .bashrc.
Date: Sat, 28 Oct 2017 09:57:33 +0200
Heya,

Marius Bakke <mbakke <at> fastmail.com> skribis:

> * gnu/system/shadow.scm (default-skeletons): Instead of testing for
> $SSH_CLIENT, check whether '$-' includes the letter 'i'.

That’s an improvement indeed, LGTM!

Ludo’, who can still learn new things about Bash after all these years.




Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Sat, 28 Oct 2017 08:00:01 GMT) Full text and rfc822 format available.

Message #17 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Marius Bakke <mbakke <at> fastmail.com>
Cc: 29035 <at> debbugs.gnu.org
Subject: Re: [bug#29035] [PATCH 2/2] skel: Return early from .bashrc when the
 shell is non-interactive.
Date: Sat, 28 Oct 2017 09:59:10 +0200
Marius Bakke <mbakke <at> fastmail.com> skribis:

> * gnu/system/shadow.scm (default-skeletons): Add return statement.
> ---
>  gnu/system/shadow.scm | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
> index 475960b89..8d8dbc70a 100644
> --- a/gnu/system/shadow.scm
> +++ b/gnu/system/shadow.scm
> @@ -163,6 +163,9 @@ then
>      # (as in \"ssh host command\").  Source /etc/profile so we
>      # get $PATH and other essential variables.
>      source /etc/profile
> +
> +    # Don't do anything else.
> +    return
>  fi

LGTM, thanks!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Sun, 29 Oct 2017 10:18:01 GMT) Full text and rfc822 format available.

Message #20 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: Marius Bakke <mbakke <at> fastmail.com>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 29035 <at> debbugs.gnu.org
Subject: Re: [bug#29035] [PATCH 1/2] skel: Test for interactive shell instead
 of $SSH_CLIENT in .bashrc.
Date: Sun, 29 Oct 2017 11:17:10 +0100
[Message part 1 (text/plain, inline)]
Ludovic Courtès <ludo <at> gnu.org> writes:

> Heya,
>
> Marius Bakke <mbakke <at> fastmail.com> skribis:
>
>> * gnu/system/shadow.scm (default-skeletons): Instead of testing for
>> $SSH_CLIENT, check whether '$-' includes the letter 'i'.
>
> That’s an improvement indeed, LGTM!

I realized this will source /etc/profile twice when bash is invoked as
'bash -l -c foo', which isn't great.  It also assumes /etc/profile
exists at all, which might not hold true e.g. in a container.

The main motivation for this commit is to make things like
'git-receive-pack', 'rsync' etc work out-of-the-box when installed in
a user profile.  The test for `cat` was ineffective on OpenSSH since it
has a default PATH set to "/run/current-system/profile/bin".

I've tested adding ~/.guix-profile/bin to the compiled-in default
OpenSSH PATH instead, and it works.  WDYT of this series?

[bashrc.patch (text/x-patch, inline)]
From fc37dd6dfb6beab9cc4e52de7b7c98946125e7cc Mon Sep 17 00:00:00 2001
From: Marius Bakke <mbakke <at> fastmail.com>
Date: Sun, 29 Oct 2017 10:31:25 +0100
Subject: [PATCH 1/3] gnu: openssh: Add user profiles to the default PATH.

* gnu/packages/ssh.scm (openssh)[arguments]<#:configure-flags>: Add
'~/guix-profile/bin' to '--with-default-path' arguments.
---
 gnu/packages/ssh.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/ssh.scm b/gnu/packages/ssh.scm
index 8317f29cd..2aeeeae1e 100644
--- a/gnu/packages/ssh.scm
+++ b/gnu/packages/ssh.scm
@@ -149,7 +149,9 @@ a server that supports the SSH-2 protocol.")
       #:configure-flags  `("--sysconfdir=/etc/ssh"
 
                            ;; Default value of 'PATH' used by sshd.
-                          "--with-default-path=/run/current-system/profile/bin"
+                           ,(string-append "--with-default-path="
+                                           "/run/current-system/profile/bin:"
+                                           "~/.guix-profile/bin")
 
                           ;; configure needs to find krb5-config
                           ,(string-append "--with-kerberos5="
-- 
2.14.3


From cc817dd809c85571d3e54a226ff16a7a3aa5bdae Mon Sep 17 00:00:00 2001
From: Marius Bakke <mbakke <at> fastmail.com>
Date: Sun, 29 Oct 2017 11:07:49 +0100
Subject: [PATCH 2/3] system: Don't try to source /etc/profile in '.bashrc'
 skeleton.

* gnu/system/shadow.scm (default-skeletons)[bashrc]: Remove test for $SSH_CLIENT.
---
 gnu/system/shadow.scm | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 236807c70..f6484f85e 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -157,15 +157,6 @@ if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n"))
 # honor it and otherwise use /bin/sh.
 export SHELL
 
-if [ -n \"$SSH_CLIENT\" -a -z \"`type -P cat`\" ]
-then
-    # We are being invoked from a non-interactive SSH session
-    # (as in \"ssh host command\") but 'cat' cannot be found
-    # in $PATH.  Source /etc/profile so we get $PATH and other
-    # essential variables.
-    source /etc/profile
-fi
-
 # Adjust the prompt depending on whether we're in 'guix environment'.
 if [ -n \"$GUIX_ENVIRONMENT\" ]
 then
-- 
2.14.3


From 53761ac682cf0de4161c40aa7ec5372a2070c2b2 Mon Sep 17 00:00:00 2001
From: Marius Bakke <mbakke <at> fastmail.com>
Date: Sat, 28 Oct 2017 01:19:01 +0200
Subject: [PATCH 3/3] system: Return early in skeleton '.bashrc' when the shell
 is non-interactive.

* gnu/system/shadow.scm (default-skeletons)[bashrc]: Test if $- includes the
letter 'i', and return if it doesn't.
---
 gnu/system/shadow.scm | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index f6484f85e..e1ff3c42d 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -157,6 +157,12 @@ if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n"))
 # honor it and otherwise use /bin/sh.
 export SHELL
 
+# If not running interactively, don't do anything else.
+if [[ $- != *i* ]]
+then
+    return
+fi
+
 # Adjust the prompt depending on whether we're in 'guix environment'.
 if [ -n \"$GUIX_ENVIRONMENT\" ]
 then
-- 
2.14.3

[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Sun, 29 Oct 2017 14:25:02 GMT) Full text and rfc822 format available.

Message #23 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Marius Bakke <mbakke <at> fastmail.com>
Cc: 29035 <at> debbugs.gnu.org
Subject: Re: [bug#29035] [PATCH 1/2] skel: Test for interactive shell instead
 of $SSH_CLIENT in .bashrc.
Date: Sun, 29 Oct 2017 15:24:44 +0100
Hi Marius!

Marius Bakke <mbakke <at> fastmail.com> skribis:

> Ludovic Courtès <ludo <at> gnu.org> writes:
>
>> Heya,
>>
>> Marius Bakke <mbakke <at> fastmail.com> skribis:
>>
>>> * gnu/system/shadow.scm (default-skeletons): Instead of testing for
>>> $SSH_CLIENT, check whether '$-' includes the letter 'i'.
>>
>> That’s an improvement indeed, LGTM!
>
> I realized this will source /etc/profile twice when bash is invoked as
> 'bash -l -c foo', which isn't great.  It also assumes /etc/profile
> exists at all, which might not hold true e.g. in a container.

OK.  (Though GuixSD containers do have /etc/profile, don’t they?)

> The main motivation for this commit is to make things like
> 'git-receive-pack', 'rsync' etc work out-of-the-box when installed in
> a user profile.  The test for `cat` was ineffective on OpenSSH since it
> has a default PATH set to "/run/current-system/profile/bin".
>
> I've tested adding ~/.guix-profile/bin to the compiled-in default
> OpenSSH PATH instead, and it works.  WDYT of this series?

OK.

I think it would make sense to add a test to (gnu tests ssh) for this,
because it’s one of these things that annoy everyone.

> From fc37dd6dfb6beab9cc4e52de7b7c98946125e7cc Mon Sep 17 00:00:00 2001
> From: Marius Bakke <mbakke <at> fastmail.com>
> Date: Sun, 29 Oct 2017 10:31:25 +0100
> Subject: [PATCH 1/3] gnu: openssh: Add user profiles to the default PATH.
>
> * gnu/packages/ssh.scm (openssh)[arguments]<#:configure-flags>: Add
> '~/guix-profile/bin' to '--with-default-path' arguments.
> ---
>  gnu/packages/ssh.scm | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/packages/ssh.scm b/gnu/packages/ssh.scm
> index 8317f29cd..2aeeeae1e 100644
> --- a/gnu/packages/ssh.scm
> +++ b/gnu/packages/ssh.scm
> @@ -149,7 +149,9 @@ a server that supports the SSH-2 protocol.")
>        #:configure-flags  `("--sysconfdir=/etc/ssh"
>  
>                             ;; Default value of 'PATH' used by sshd.
> -                          "--with-default-path=/run/current-system/profile/bin"
> +                           ,(string-append "--with-default-path="
> +                                           "/run/current-system/profile/bin:"
> +                                           "~/.guix-profile/bin")

If sshd performs tilde expansion, that’s fine with me.

Should we do something similar for lsh and Dropbear?

> From cc817dd809c85571d3e54a226ff16a7a3aa5bdae Mon Sep 17 00:00:00 2001
> From: Marius Bakke <mbakke <at> fastmail.com>
> Date: Sun, 29 Oct 2017 11:07:49 +0100
> Subject: [PATCH 2/3] system: Don't try to source /etc/profile in '.bashrc'
>  skeleton.
>
> * gnu/system/shadow.scm (default-skeletons)[bashrc]: Remove test for $SSH_CLIENT.

OK.

> From 53761ac682cf0de4161c40aa7ec5372a2070c2b2 Mon Sep 17 00:00:00 2001
> From: Marius Bakke <mbakke <at> fastmail.com>
> Date: Sat, 28 Oct 2017 01:19:01 +0200
> Subject: [PATCH 3/3] system: Return early in skeleton '.bashrc' when the shell
>  is non-interactive.
>
> * gnu/system/shadow.scm (default-skeletons)[bashrc]: Test if $- includes the
> letter 'i', and return if it doesn't.

OK.

Thank you!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Sun, 29 Oct 2017 20:08:01 GMT) Full text and rfc822 format available.

Message #26 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: Marius Bakke <mbakke <at> fastmail.com>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 29035 <at> debbugs.gnu.org
Subject: Re: [bug#29035] [PATCH 1/2] skel: Test for interactive shell instead
 of $SSH_CLIENT in .bashrc.
Date: Sun, 29 Oct 2017 21:07:40 +0100
[Message part 1 (text/plain, inline)]
Ludovic Courtès <ludo <at> gnu.org> writes:

> Hi Marius!
>
> Marius Bakke <mbakke <at> fastmail.com> skribis:
>
>> Ludovic Courtès <ludo <at> gnu.org> writes:
>>
>>> Heya,
>>>
>>> Marius Bakke <mbakke <at> fastmail.com> skribis:
>>>
>>>> * gnu/system/shadow.scm (default-skeletons): Instead of testing for
>>>> $SSH_CLIENT, check whether '$-' includes the letter 'i'.
>>>
>>> That’s an improvement indeed, LGTM!
>>
>> I realized this will source /etc/profile twice when bash is invoked as
>> 'bash -l -c foo', which isn't great.  It also assumes /etc/profile
>> exists at all, which might not hold true e.g. in a container.
>
> OK.  (Though GuixSD containers do have /etc/profile, don’t they?)

I only checked `guix environment -C` (no further arguments!).

>> The main motivation for this commit is to make things like
>> 'git-receive-pack', 'rsync' etc work out-of-the-box when installed in
>> a user profile.  The test for `cat` was ineffective on OpenSSH since it
>> has a default PATH set to "/run/current-system/profile/bin".
>>
>> I've tested adding ~/.guix-profile/bin to the compiled-in default
>> OpenSSH PATH instead, and it works.  WDYT of this series?
>
> OK.
>
> I think it would make sense to add a test to (gnu tests ssh) for this,
> because it’s one of these things that annoy everyone.

Good idea.  I came up with this:

[0001-tests-ssh-Make-sure-we-can-run-commands-from-PATH.patch (text/x-patch, inline)]
diff --git a/gnu/tests/ssh.scm b/gnu/tests/ssh.scm
index 41be36035..6d367dc75 100644
--- a/gnu/tests/ssh.scm
+++ b/gnu/tests/ssh.scm
@@ -169,6 +170,33 @@ root with an empty password."
                  (call-with-remote-input-file sftp-session witness
                                               read)))))
 
+          ;; Connect to the guest over SSH.  Make sure we can run commands
+          ;; from the system profile.
+          (test-equal "run executables from system profile"
+            #t
+            (call-with-connected-session/auth
+             (lambda (session)
+               (let ((channel (make-channel session)))
+                 (channel-open-session channel)
+                 (channel-request-exec
+                  channel
+                  (string-append
+                   "mkdir -p /root/.guix-profile/bin && "
+                   "touch /root/.guix-profile/bin/witness && "
+                   "chmod 755 /root/.guix-profile/bin/witness"))
+                 (zero? (channel-get-exit-status channel))))))
+
+          ;; Connect to the guest over SSH.  Make sure we can run commands
+          ;; that only exist in the user profile.
+          (test-equal "run executable from user profile"
+            #t
+            (call-with-connected-session/auth
+             (lambda (session)
+               (let ((channel (make-channel session)))
+                 (channel-open-session channel)
+                 (channel-request-exec channel "witness")
+                 (zero? (channel-get-exit-status channel))))))
+
           (test-end)
           (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
 
[Message part 3 (text/plain, inline)]
It works as expected with both approaches (changing .bashrc, and
changing "--with-default-path").  WDYT?

>> From fc37dd6dfb6beab9cc4e52de7b7c98946125e7cc Mon Sep 17 00:00:00 2001
>> From: Marius Bakke <mbakke <at> fastmail.com>
>> Date: Sun, 29 Oct 2017 10:31:25 +0100
>> Subject: [PATCH 1/3] gnu: openssh: Add user profiles to the default PATH.
>>
>> * gnu/packages/ssh.scm (openssh)[arguments]<#:configure-flags>: Add
>> '~/guix-profile/bin' to '--with-default-path' arguments.
>> ---
>>  gnu/packages/ssh.scm | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/gnu/packages/ssh.scm b/gnu/packages/ssh.scm
>> index 8317f29cd..2aeeeae1e 100644
>> --- a/gnu/packages/ssh.scm
>> +++ b/gnu/packages/ssh.scm
>> @@ -149,7 +149,9 @@ a server that supports the SSH-2 protocol.")
>>        #:configure-flags  `("--sysconfdir=/etc/ssh"
>>  
>>                             ;; Default value of 'PATH' used by sshd.
>> -                          "--with-default-path=/run/current-system/profile/bin"
>> +                           ,(string-append "--with-default-path="
>> +                                           "/run/current-system/profile/bin:"
>> +                                           "~/.guix-profile/bin")
>
> If sshd performs tilde expansion, that’s fine with me.

Unfortunately, I think the tilde is expanded by the shell, and this made
me look up how POSIX handles tilde in PATH.  It appears bash, when
invoked with '--posix', does *not* perform tilde expansion if it appears
as the first character in a PATH element:

<https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html>
(note 16)

So while it works with "bash" as the login shell, unexpected results may
occur with others.  It doesn't seem impossible to patch OpenSSH to
perform this expansion, though:

<https://github.com/openssh/openssh-portable/blob/b7548b12a6b2b4abf4d057192c353147e0abba08/session.c#L998>
(_PATH_STDPATH is the --with-default-path)

> Should we do something similar for lsh and Dropbear?

Probably.  Since we have a system test, it's easy to experiment with.
For now I think this .bashrc workaround might be the easiest approach,
which makes the above test pass for both OpenSSH and Dropbear:

[0001-system-Test-for-interactive-shell-instead-of-cat-in-.patch (text/x-patch, inline)]
From 6f4dfbea9cd92a3b03d7e1db89c75a88f4495ba5 Mon Sep 17 00:00:00 2001
From: Marius Bakke <mbakke <at> fastmail.com>
Date: Sun, 29 Oct 2017 21:02:19 +0100
Subject: [PATCH] system: Test for interactive shell instead of `cat` in
 skeleton '.bashrc'.

* gnu/system/shadow.scm (default-skeletons)[bashrc]: Wrap $SSH_CLIENT test in
a conditional testing for interactive shell.
---
 gnu/system/shadow.scm | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 236807c70..58613e620 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -157,13 +157,12 @@ if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n"))
 # honor it and otherwise use /bin/sh.
 export SHELL
 
-if [ -n \"$SSH_CLIENT\" -a -z \"`type -P cat`\" ]
+if [[ $- != *i* ]]
 then
-    # We are being invoked from a non-interactive SSH session
-    # (as in \"ssh host command\") but 'cat' cannot be found
-    # in $PATH.  Source /etc/profile so we get $PATH and other
-    # essential variables.
-    source /etc/profile
+    # We are being invoked from a non-interactive shell.  If this
+    # is an SSH session (as in \"ssh host command\"), source
+    # /etc/profile so we get PATH and other essential variables.
+    [[ -n \"$SSH_CLIENT\" ]] && source /etc/profile
 fi
 
 # Adjust the prompt depending on whether we're in 'guix environment'.
-- 
2.14.3

[Message part 5 (text/plain, inline)]
Thanks for the fast replies, and sorry for the round-trip!
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#29035; Package guix-patches. (Sun, 29 Oct 2017 21:27:01 GMT) Full text and rfc822 format available.

Message #29 received at 29035 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Marius Bakke <mbakke <at> fastmail.com>
Cc: 29035 <at> debbugs.gnu.org
Subject: Re: [bug#29035] [PATCH 1/2] skel: Test for interactive shell instead
 of $SSH_CLIENT in .bashrc.
Date: Sun, 29 Oct 2017 22:26:16 +0100
Heya!

Marius Bakke <mbakke <at> fastmail.com> skribis:

> Ludovic Courtès <ludo <at> gnu.org> writes:

[...]

>> I think it would make sense to add a test to (gnu tests ssh) for this,
>> because it’s one of these things that annoy everyone.
>
> Good idea.  I came up with this:

Perfect!

> It works as expected with both approaches (changing .bashrc, and
> changing "--with-default-path").  WDYT?

Given that --with-default-path doesn’t quite work (due to lack of tilde
expansion), I suppose we should go for .bashrc?

> So while it works with "bash" as the login shell, unexpected results may
> occur with others.  It doesn't seem impossible to patch OpenSSH to
> perform this expansion, though:
>
> <https://github.com/openssh/openssh-portable/blob/b7548b12a6b2b4abf4d057192c353147e0abba08/session.c#L998>
> (_PATH_STDPATH is the --with-default-path)

That’s maybe more than we’d like to do, and also doesn’t help with the
two other SSH implementations.

>> Should we do something similar for lsh and Dropbear?
>
> Probably.  Since we have a system test, it's easy to experiment with.
> For now I think this .bashrc workaround might be the easiest approach,
> which makes the above test pass for both OpenSSH and Dropbear:
>
> From 6f4dfbea9cd92a3b03d7e1db89c75a88f4495ba5 Mon Sep 17 00:00:00 2001
> From: Marius Bakke <mbakke <at> fastmail.com>
> Date: Sun, 29 Oct 2017 21:02:19 +0100
> Subject: [PATCH] system: Test for interactive shell instead of `cat` in
>  skeleton '.bashrc'.
>
> * gnu/system/shadow.scm (default-skeletons)[bashrc]: Wrap $SSH_CLIENT test in
> a conditional testing for interactive shell.

LGTM.

Thank you!

Ludo’.




Reply sent to Marius Bakke <mbakke <at> fastmail.com>:
You have taken responsibility. (Wed, 01 Nov 2017 20:39:02 GMT) Full text and rfc822 format available.

Notification sent to Marius Bakke <mbakke <at> fastmail.com>:
bug acknowledged by developer. (Wed, 01 Nov 2017 20:39:02 GMT) Full text and rfc822 format available.

Message #34 received at 29035-done <at> debbugs.gnu.org (full text, mbox):

From: Marius Bakke <mbakke <at> fastmail.com>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 29035-done <at> debbugs.gnu.org
Subject: Re: [bug#29035] [PATCH 1/2] skel: Test for interactive shell instead
 of $SSH_CLIENT in .bashrc.
Date: Wed, 01 Nov 2017 21:38:03 +0100
[Message part 1 (text/plain, inline)]
Pushed revised series as 83a7a88f932..5d7141cd284e.
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 30 Nov 2017 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 207 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.