Deployer: Compatibility with the Win32 port of OpenSSH

Created on 24 Apr 2018  路  6Comments  路  Source: deployphp/deployer

| Q | A
| ----------------- | ---
| Issue Type | Bug
| Deployer Version | 6.2.0
| Local Machine OS | Windows
| Remote Machine OS | Ubuntu 16.04

Description

When using the Win32 port of OpenSSH the ssh command needs to be enclosed by double quotes, because windows executables need double quotes for arguments.

E.g. (when using the Win32 port of OpenSSH)

> ssh.exe [email protected] 'echo "foobar"'
bash: echo foobar: command not found
> ssh.exe [email protected] "echo 'foobar'"
foobar

The Client class produces a command with single quotes, see https://github.com/deployphp/deployer/blob/master/src/Ssh/Client.php#L86

When one changes this to

$ssh = "ssh $sshArguments $host $become \"$shellCommand; printf '[exit_code:%s]' $?;\"";

it will work with the windows ssh.exe, but then shell expansion would be applied to the $shellCommand ($var would be evaluated), which could cause problem (although that change works fine for me).

One way around this, would be to check which ssh.exe is used and then apply the correct quoting style (when using windows $var will not be evaluated, so it should be safe).

$sshVersionProcess = new Process('ssh -V');
$sshVersionProcess->run();
// the version info is on STDERR
if(strpos($sshVersionProcess->getErrorOutput(), 'OpenSSH_for_Windows') !== false){
    $ssh = "ssh $sshArguments $host $become \"$shellCommand; printf '[exit_code:%s]' $?;\"";
} else {
    $ssh = "ssh $sshArguments $host $become '$shellCommand; printf \"[exit_code:%s]\" $?;'";
}

It would be nice to get the version info only once, but i'm not sure where...

Should i create a pull request for my supposed solution?

Steps to reproduce

Execute deployer deploy with the Win32 port of OpenSSH.

bug

Most helpful comment

I ended up using capistrano again 馃槈

For the moment that seems to work flawless with windows.

Looking forward to 7.0 to try again.

All 6 comments

This will probably fix https://github.com/deployphp/deployer/issues/1436.

Maybe one could only rely on just checking if php is run from windows or not (with the PHP_OS-constant) since when it is run from windows, it will need double quotes regardless where ssh.exe comes from (e.g. the older one mentioned in 1436).

if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
    $ssh = "ssh $sshArguments $host $become \"$shellCommand; printf '[exit_code:%s]' $?;\"";
} else {
    $ssh = "ssh $sshArguments $host $become '$shellCommand; printf \"[exit_code:%s]\" $?;'";
}

I ended up merging all the fixes.
https://github.com/digizijn/deployer/

I ended up using capistrano again 馃槈

For the moment that seems to work flawless with windows.

Looking forward to 7.0 to try again.

Works for me on Windows 10.

@marcharding it works for me too. Try to submit a PR to fix this.
This issue (#1640 ) also mention the solution.

Is it working now? Ok to close?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sweebee picture sweebee  路  3Comments

ElForastero picture ElForastero  路  3Comments

dima-stefantsov picture dima-stefantsov  路  5Comments

brunodevel picture brunodevel  路  3Comments

greatwitenorth picture greatwitenorth  路  4Comments