warpdotdev / Warp

Warp is a modern, Rust-based terminal with AI built in so you and your team can build great software, faster.
https://warp.dev
Other
20.99k stars 359 forks source link

Warp doesn't represent itself as interactive shell if shell on remote host differs from localhost #2228

Open Shtsh opened 1 year ago

Shtsh commented 1 year ago

Discord username (optional)

No response

Describe the bug

My shell on local host is zsh.

If I connect via ssh to remote host which uses bash as a shell the session in not considered as interactive. As result it breaks some scripts which are supposed to be loaded for real users but not for automation. I use proxy to connect to the remote host

From ~/.ssh/config ProxyCommand ssh -q hostname ssh-proxy %h %p

Other terminals like iTerm2 work without issues

To Reproduce

Locally in zsh

[[ -o login ]] && echo "Login Shell" || "Not login shell"
Login Shell

echo $SHELL
/bin/zsh

zsh --version
zsh 5.9 (arm-apple-darwin21.3.0)

After that ssh to the remote host which uses bash

shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
Not login shell

echo $SHELL
/bin/bash

bash --version | head -n1
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

Expected behaviour

No response

Screenshots

No response

Operating System

MacOS

OS Version

12.6

Shell Version

GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

Warp Version

v0.2022.11.14.14.55.stable_01

Additional context

No response

Does this block you from using Warp daily?

No

Warp Internal (ignore): linear-label:b8107fdf-ba31-488d-b103-d271c89cac3e

No response

dannyneira commented 1 year ago

So sorry about this issue, we will post any updates on questions here.

szgupta commented 1 year ago

Hey @Shtsh, thank you for pointing this out! Out of curiosity, when you say

As result it breaks some scripts which are supposed to be loaded for real users

how are these scripts being run (are they in some login script)? Are they conditioned on whether or not the shell is a login shell? Although the shell isn't a login shell, we do source the same startup files that would be sourced during the initialization of a login shell (i.e. /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile)

Shtsh commented 1 year ago

Hey @szgupta

On the remote server we load /etc/profile which calls . /etc/profile.d/script.sh In this script we have a check if it is login shell to activate python virtualenv. We don't need such logic for non-interactive sessions to not to break scp or something else.

if shopt -q login_shell; then
    . /usr/local/venv/some_dir/bin/activate
    PATH="$PATH:/usr/local/git_tree/some_dir/bin"
    export DJANGO_SETTINGS_MODULE=value
    export PYTHONPATH=/usr/local/some_dir
    export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt
    PS1="[\u@\h \W]\\$ "
fi
szgupta commented 1 year ago

@Shtsh I see. And just to confirm, is /etc/profile.d/script.sh invoked from anywhere other than /etc/profile?

Shtsh commented 1 year ago

No, it is invoked from /etc/profile

szgupta commented 1 year ago

Gotcha -- and are you sure /etc/profile is invoked for non-login shells (i.e. do you need the if shopt -q login_shell check)? AFAICT from Bash's documentation, it shouldn't be. Documentation

Although Warp doesn't mark it as a login shell (it should -- this is indeed a bug), it does source the right login scripts for login shells (including /etc/profile).

(Also, I realize you mentioned "non-interactive" which is slightly different from non-login. Though from the docs, it shouldn't be run for neither non-interactive nor non-login).

Shtsh commented 1 year ago

AFAIK we had issues with scp before this check but I cannot say that for sure and since then the configuration could've changed. It's been a while since this logic was introduced.