Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331587 - Remote Build fails with "/bin/sh: declare: not found" on systems with dash (e.g. Ubuntu)
Summary: Remote Build fails with "/bin/sh: declare: not found" on systems with dash (e...
Status: RESOLVED FIXED
Alias: None
Product: PTP
Classification: Tools
Component: Remote Tools (show other bugs)
Version: 4.0.5   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Greg Watson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-01 14:07 EST by Roland Schulz CLA
Modified: 2011-02-07 10:10 EST (History)
0 users

See Also:


Attachments
environment patch (5.27 KB, patch)
2010-12-02 10:18 EST, Greg Watson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Schulz CLA 2010-12-01 14:07:36 EST
Remote Tools uses /bin/sh for remote execution (e.g. in KillableExecution). But it implicitly assumes that the shell is a bash/zsh shell because it uses the "declare -x" in org.eclipse.ptp.remotetools.internal.common.RemoteScript.getScriptString()
(I don't see why zsh wouldn't work, but I haven't tested that it does. Declare is not supported by tcsh or dash. So those two are guaranteed not to work). 

I see two options
- After connecting find the path to a supported shell. Thus test that /bin/sh is a bash/zsh and if not find the path to bash/zsh. If no bash/zsh is found a error has to be shown.
- Or test what shell /bin/sh is and if it is not a bash/zsh replace any bash specific commands with the correct commands for dash/tcsh/...

The 2nd has the advantage that it would work on machines without bash. The disadvantage is that all script commands have to be tested for all shells. I think this is a maintenance nightmare. Because bash is as far as I know very widely available I would favor option 1.
Comment 1 Greg Watson CLA 2010-12-02 10:18:35 EST
Created attachment 184358 [details]
environment patch
Comment 2 Greg Watson CLA 2010-12-02 10:18:51 EST
Another alternative would be to remove the dependency on the shell at all. I noticed that ChannelSession provides a setEnv method that could be used instead. Can you see if this patch works for you?
Comment 3 Roland Schulz CLA 2010-12-02 12:57:43 EST
Great! This makes it work for dash on Ubuntu. 

org.eclipse.ptp.remotetools.internal.ssh.ControlChannel.open(IProgressMonitor) (line 86) still uses export.

Otherwise I can't find any other bash specific constructs. But I'm not sure whether there are others I have missed (and don't show up in the small test I have done with Ubuntu).
Comment 4 Greg Watson CLA 2010-12-03 08:50:23 EST
Unfortunately it looks like environment variables are disabled in sshd by default. Even when enabled, there are only a maximum of 128 vars allowed (in OpenSSH anyway). 

Looking at the different shells, it seems that dash, bash, zsh, ksh, and sh all support "export A=B C=D". I think the easiest option would be to use "export" instead of "declare". The only time this would fail would be if /bin/sh was a link to csh or tsch, but how likely is this?
Comment 5 Roland Schulz CLA 2010-12-03 14:37:32 EST
I haven't seen any machine with csh as /bin/sh (but I don't any Unix other than Linux). But according to http://jira.atlassian.com/browse/JRA-9102 the /bin/sh used in Solaris doesn't support export A=B. But it does support A=B, and then in the next line export A.
Comment 6 Greg Watson CLA 2011-02-07 10:10:41 EST
Changed to use 'export "var=val"' for each variable in HEAD and 4.0.